Mám funkciu, ktorá má byť volaná z multiprocessing pool.map s viacerými argumentmi.
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()
ale dáva mi nasledujúcu chybu
TypeError: printed() takes exactly 2 arguments (1 given)
Skúšal som riešenia z iných odpovedí, ale nepracujú pre mňa. Ako to môžem vyriešiť a čo je dôvodom tohto problému (nedostal som uhorku POV)
odpovede:
1 pre odpoveď č. 1Mali by ste dávať args v poli
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()