Thursday, 8 August 2013

Multiprocessing, does join prevent processes from working in parallel?

Multiprocessing, does join prevent processes from working in parallel?

I'm quite new to multiprocessing, and have been trying to find an answer
to this question but not succeeding.
Given two processes, if I use .join, does the second process begin in
parallel with the first process, or does it wait until the first process
is completed?
If the latter, how do I let the processes work in tandem?
import multiprocessing
def worker():
x = 0
for i in range(2000000):
x+=1
print x
def worker2():
x = 0
for i in range(10000000):
x+=1
print x
if __name__ == '__main__':
q = multiprocessing.Process(target=worker2,)
q.start()
q.join()
p = multiprocessing.Process(target=worker,)
p.start()
p.join()

No comments:

Post a Comment