How to use multiprocessing pool.map with multiple arguments?

前端 未结 20 3468
-上瘾入骨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:56

    A better solution for python2:

    from multiprocessing import Pool
    def func((i, (a, b))):
        print i, a, b
        return a + b
    pool = Pool(3)
    pool.map(func, [(0,(1,2)), (1,(2,3)), (2,(3, 4))])
    

    2 3 4

    1 2 3

    0 1 2

    out[]:

    [3, 5, 7]

提交回复
热议问题