python - How does process join() work? -
i trying understand multiprocessing in python, wrote following program:
from multiprocessing import process numofloops = 10 #function each process def func(): = float(0.0) in xrange(0, numofloops): += 0.5 print processes = [] numofprocesses = 2 #create processes in xrange(0, numofprocesses): processes.append(process(target=func)) process in processes: process.start() #start processes process in processes: process.join() #wait each process terminate print "shouldn't statement printed @ end??" i created 2 processes executes function func(). used join() method wait each process terminate before proceeding program. doesn't mean last print statement should printed @ end of program after 2 processes have executed function? output was:
shouldn't statement printed @ end?? 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 which not expected. can explain what's going on?
it simple, waits each of running processes finish , when happens, returns.

Comments
Post a Comment