Python Multiprocessing -- how to make all processes enter a code block at the same time - python-multiprocessing

My code looks like this, for each process:
def foo():
while True:
a = func1()
func2()
and I wish to collect the results of func1 from different processes and process them in func2. Processes may have to enter func2 together, since a varies across iterations and across processes.
Is there any way to synchronize different processes so that they always enter func2 at the same time?
More explanation:
Say func1 gives out values from number series 1,2,3...
and func2 is to add the value a from every process up. What I hope to achieve:
process 1 execute func1 and gives out a=1
process 2 execute func1 and gives out a=2
process 1 and 2 execute func2:1+2=3
process 1 execute func1 and gives out a=3
process 2 execute func1 and gives out a=4
process 1 and 2 execute func2:3+4=7
What I actually achieved :(
process 1 execute func1 and gives out a=1
process 2 execute func1 and gives out a=2
process 1 and 2 execute func2:1+2=3
process 1 execute func1 and gives out a=3
process 1 execute func2:2+3=5
So maybe they need to enter func2 at the same time?

Related

After command usage in Tcl

So my understanding is that after command can be used to delay the execution of a script or a command for certain ms but when i execute the below command, the output is printed immediately
Command:
after 4000 [list puts "hello"]
Output:
hello
after#0
Question: Why was the output not delayed for 4s here?
That what you wrote works; I just tried it at a tclsh prompt like this:
% after 4000 [list puts "hello"]; after 5000 set x 1; vwait x
Did you write something else instead, such as this:
after 4000 [puts "hello"]
In this case, instead of delaying the execution of puts, you'd be calling it immediately and using its result (the empty string) as the argument to after (which is valid, but useless).
Think of [list …] as a special kind of quoting.
The other possibility when running interactively is that you take several seconds between running the after and starting the event loop (since the callbacks are only ever run by the event loop). You won't see that in wish of course — that's always running an event loop — but it's possible in tclsh as that doesn't start an event loop by default. But I'd put that as a far distant second in terms of probability to omitting the list word…

Minecraft execute if scoreboard value = 0 with command blocks

I want to make a command block that executes "say Zero pigs alive" when the amount of pigs on the map is zero. I made a pig count with a scoreboard on the side that shows the amount of pigs when I press on the button, but I want a command to be executed when the amount is zero on the scoreboard. Does anyone know how I can do this?
This is what is looks like, when the 16 is a zero, so no pigs are in the map, it needs to activate the next command block that says "Zero pigs alive"
Yes , this is possible. You would want to do something along the lines of
execute if score test pig matches 0 run say Zero pigs alive
But, you can check if there are no entities alive and say your message all in one command, which would be more efficient. An example would be
execute unless entity #e[type=pig] run say Zero pigs alive```

I want to execute a JCL step no matter what the RC of previous step is?

There are 3 steps in my JCL:
STEP 1: process
STEP 2: NDM
STEP 3: DELETE OUTPUT after NDM
What I want to accomplish?
I want to execute STEP 3 no matter what the return code of step 2 is.
I tried this:
COND=(16,GT) and COND=(16,ST,STEP 2) but it's not doing what I want to do.
Using COND=EVEN has the potential pitfall that the STEP will run even if the previous step ABENDS. Coding COND=(0,GT,STEP2) should allow the step to run but not if there is an ABEND.
Alternately you could use IF/THEN/ELSE/ENDIF coding.
e.g.
//STEP2 EXEC PGM=NDM
//IF STEP2.RC >= 0 THEN
//STEP3 EXEC PGM=???
//ENDIF
or
//STEP2 EXEC PGM=NDM
//IF STEP2.RC GE 0 THEN
//STEP3 EXEC PGM=???
//ENDIF
i.e. either >= or GE can be used.
You may find this helpful IF/THEN/ELSE/ENDIF Statement Construct
or for the COND parameter COND Parameter
Try COND=EVEN on your final step’s EXEC statement.
From the documetnation:
COND=EVEN tells MVS to execute this job step EVEN IF a prior step in
the same job abends, unless the job is canceled by the MVS
operator.
There's also a COND=ONLY:
COND=ONLY tells MVS to execute this job step ONLY IF a prior step in
the same job abends.
Explanation of COND:
COND is fairly counter-intuitive. The description is:
If none of these tests is satisfied, the system executes the job step;
if any test is satisfied, the system skips the job step on which the
COND= parameter is coded.
So your COND=(16,GT) means "If 16 is greater than the return code from any previous steps, don't execute this step". So this step would only execute if ALL the previous steps finished with a RC > 16.
COND=(16,ST,STEP 2) is invalid - ST is not a valid condition. Valid tests are :
EQ - equal
LT - less than
LE - less than or equal to
NE - not equal
GT - greater than
GE - greater than or equal to
To make a step run, no matter what the condition codes from previous steps are, you could code COND=(0,GT), which means 'if 0 is greater than any previous return code (which it won't be), skip this step.'.
To be safe, you could code:
COND=((0,GT),EVEN)
as EVEN will cause this step to execute even if a previous step ABENDs.

Bamboo vs CxxTest

When I create a plan in Bamboo and add a task for running CxxTest test code(running function TS_ASSERT(1==1) or st). When I try to run for checking failure (TS_ASSERT(1==2)), this test case is fail and Bamboo output a log as:
12-Mar-2014 15:12:07 Failed 1 and Skipped 0 of 2 tests
12-Mar-2014 15:12:07 Success rate: 50%
12-Mar-2014 15:12:07 Failing task since return code was 1 while expected 0
So, does anyone here know why bamboo can understand the test result, and what is the return code here(return code was 1 while expected 0)?
From my observation, one windows, Bamboo consider value of the %ERRORLEVEL% as the result of the task. so return code was 1 while expected 0 means your task is returning 1 and Bamboo is expecting 0. Yes, it's expecting 0 since it considers any value other than 0 as failure.

File I/O in gnu parallel

I have a program that takes a single argument. I am using gnu parallel to perform parameter sweeps on this argument. Each run generates a single result, and I want to append all results into a single file, say Results.txt.
What would be a correct way to do this?
I should not have each instance open the file and write to it, as this could create conflicts and also mess up the order of results. The only way I can think of doing this is having each run generate its output in a file with a unique name, and then , when gnu parallel finishes running, merge the results into a single file using a script.
Is there a simpler way of achieving this?
What happens when multiple instances write to/read from the same file? Does gnu parallel create multiple copies, one for each instances, as it does for stdout and stderror?
thanks
If your command sends the result to stdout (standard output) the solution is trivial:
seq 1000 | parallel echo > Results.txt
GNU Parallel guarantees the output will not be mixed.
Normally GNU Parallel prints the output of a job as soon as it's completed. When jobs run for a different amount of time, this can lead to their output being mixed.
To keep the output in order, simply add -k / --keep-order parameter.
Try for example:
parallel -j4 sleep {}\; echo {} ::: 2 1 4 3
parallel -j4 -k sleep {}\; echo {} ::: 2 1 4 3