How can I recover the return value of a function passed to multiprocessing.Process?

前端 未结 12 1607
野的像风
野的像风 2020-11-22 07:36

In the example code below, I\'d like to recover the return value of the function worker. How can I go about doing this? Where is this value stored?

12条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 07:57

    The pebble package has a nice abstraction leveraging multiprocessing.Pipe which makes this quite straightforward:

    from pebble import concurrent
    
    @concurrent.process
    def function(arg, kwarg=0):
        return arg + kwarg
    
    future = function(1, kwarg=1)
    
    print(future.result())
    

    Example from: https://pythonhosted.org/Pebble/#concurrent-decorators

提交回复
热议问题