I have a function to be called from multiprocessing pool.map with multiple arguments.
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()
but it gives me following error
TypeError: printed() takes exactly 2 arguments (1 given)
I have tried solutions from other answers here but they are not working for me. How can i resolve it and what is the reason for this problem (I did not get the pickle POV)
You should be giving args in array
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()
来源:https://stackoverflow.com/questions/29427460/python-multiprocessing-pool-map-with-multiple-arguments