Python 具有多个参数的多处理池映射

Python multiprocessing pool map with multiple arguments

我有一个函数可以通过多参数调用 pool.map。

from multiprocessing import Pool
import time

def printed(num,num2):
    print 'here now '
    return num

class A(object):
    def __init__(self):
        self.pool = Pool(8)

    def callme(self):
        print self.pool.map(printed,(1,2),(3,4))
if __name__ == '__main__':
    aa = A()
    aa.callme()

但它给了我以下错误

TypeError: printed() takes exactly 2 arguments (1 given)

我在这里尝试过其他答案的解决方案,但它们对我不起作用。 我该如何解决它,这个问题的原因是什么(我没有得到 pickle POV)

你应该在数组中给出参数

from multiprocessing import Pool
import time

def printed(*args):
    print 'here now '
    return args[0][0]

class A(object):
    def __init__(self):
        self.pool = Pool(8)

    def callme(self):
        print self.pool.map(printed,[(1,2),(3,4)])
if __name__ == '__main__':
    aa = A()
    aa.callme()