0

I Want To Get Function Returning Value

How can i get this:

 def chunk1():
     return 'Hello'

p1 = Process(target=chunk1).start()

I Want To Get Chunk1 Returning Value from Process How Can i do that?

  • 1
    Does this answer your question? [How can I recover the return value of a function passed to multiprocessing.Process?](https://stackoverflow.com/questions/10415028/how-can-i-recover-the-return-value-of-a-function-passed-to-multiprocessing-proce) – Lesiak Mar 20 '20 at 22:18

1 Answers1

1

You probably want to use a Queue or something in shared memory.

https://docs.python.org/2/library/multiprocessing.html#module-multiprocessing

From that page:

# The Queue class is a near clone of Queue.Queue. For example:

from multiprocessing import Process, Queue

def f(q):
    q.put([42, None, 'hello'])

if __name__ == '__main__':
    q = Queue()
    p = Process(target=f, args=(q,))
    p.start()
    print q.get()    # prints "[42, None, 'hello']"
    p.join()

But if this is young code, you might consider concurrent.futures instead.

concurrent.futures used with a queue, EG:

How would I go about using concurrent.futures and queues for a real-time scenario?

dstromberg
  • 6,954
  • 1
  • 26
  • 27