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)

1
  • 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. Commented Jun 23, 2017 at 5:09

1 Answer 1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

I solved it by packing the variables earlier. This answer has also worked for my problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.