0
import multiprocessing

def worker1(num):
    return num + 10

def worker2(num):
    return num + 20

if __name__ == "__main__":

    p1 = multiprocessing.Process(target=worker1, args=[5])
    p2 = multiprocessing.Process(target=worker2, args=[5])

    print(p1)
    print(p2)

    p1.start()
    p2.start()

    p1.join()
    p2.join()

I am new in multiprocessing.

Here i am Implement multiprocessing with python. It is working. But, how can i get the result whatever the two functions are returning.

When i am printing p1, and p2 i am getting below result.

<Process(Process-1, initial)>
<Process(Process-2, initial)>
  • The *process* isn't the value you want. What you want is the value returned by the appropriate `worker`. You'll need to set up a communication mechanism to get that value out. – Scott Hunter May 01 '19 at 15:45

1 Answers1

2

I believe the right way to do it would be multiprocessing.manager() or multiprocessing.Queue(). Using Queue would be a simpler approach which gives you a simple shared variable which can contain the results for each process.