Using Pool map with a method of a class and a list

Chris Angelico rosuav at gmail.com
Tue Aug 6 13:38:54 EDT 2013


On Tue, Aug 6, 2013 at 6:12 PM, Luca Cerone <luca.cerone at gmail.com> wrote:
> from multiprocessing import Pool
>
> class A(object):
>    def __init__(self,x):
>        self.value = x
>    def fun(self,x):
>        return self.value**x
>
>
> l = range(10)
>
> p = Pool(4)
>
> op = p.map(A.fun,l)

Do you ever instantiate any A() objects? You're attempting to call an
unbound method without passing it a 'self'.

You may find the results completely different in Python 2 vs Python 3,
and between bound and unbound methods. In Python 3, an unbound method
is simply a function. In both versions, a bound method carries its
first argument around, so it has to be something different. Play
around with it a bit.

ChrisA



More information about the Python-list mailing list