0

I am working on multiprocessing in Python and I am stuck at this point.I want to put the a barrier so that all previous activities are performed first. This pseudocode will be better for understanding

def func1:
     #does something and returns something

def func2:
     #does something and returns something

    if __name__=='__main__':
         p1 = Process(target = func1)
         result = []
         result.append(p1.start())
         p2 = Process(target = func2)
         result.append(p2.start())
        # A Barrier here so that above all statments must be executed before the next one
         print(result)

1 Answers1

2

What you're looking for is Process.join()

You would use it like this:

def func1:
     #does something and returns something

def func2:
     #does something and returns something

if __name__=='__main__':
     p1 = Process(target = func1)
     result = []
     result.append(p1.start())
     p2 = Process(target = func2)
     result.append(p2.start())
     p1.join()
     p2.join()
     print(result)

Also the way you're capturing the results from the function is incorrect. Look at this answer for details on how to retrieve results from a process: How can I recover the return value of a function passed to multiprocessing.Process?

Aziz Sonawalla
  • 2,482
  • 1
  • 5
  • 6