How to use multiprocessing pool.map with multiple arguments?

前端 未结 20 3499
-上瘾入骨i
-上瘾入骨i 2020-11-21 11:24

In the Python multiprocessing library, is there a variant of pool.map which supports multiple arguments?

text = "test"
def         


        
20条回答
  •  时光取名叫无心
    2020-11-21 11:47

    I think the below will be better

    def multi_run_wrapper(args):
       return add(*args)
    def add(x,y):
        return x+y
    if __name__ == "__main__":
        from multiprocessing import Pool
        pool = Pool(4)
        results = pool.map(multi_run_wrapper,[(1,2),(2,3),(3,4)])
        print results
    

    output

    [3, 5, 7]
    

提交回复
热议问题