1

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)

  • marked as duplicate after more than 2 years. However, the question was in context of being used with pickle. The solution was to change definition of printed method `def printed(*args):` as mentioned in answer. – Muhammad Umar Farooq Jun 23 '17 at 05:09

1 Answers1

1

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()
pnv
  • 2,985
  • 5
  • 29
  • 36