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

2013-08-07 Thread Luca Cerone
Thanks for the help Peter! > > > > >> def make_instancemethod(inst, methodname): > > >> return getattr(inst, methodname) > > > > > > This is just getattr -- you can replace the two uses of > > > make_instancemethod with getattr and delete this ;). > > > > D'oh ;) -- http://mail.py

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

2013-08-07 Thread Joshua Landau
On 7 August 2013 23:26, Luca Cerone wrote: > Thanks for the post. > I actually don't know exactly what can and can't be pickles.. I just try it and see what works ;). The general idea is that if it is module-level it can be pickled and if it is defined inside of something else it cannot. It depe

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

2013-08-07 Thread Luca Cerone
Thanks for the post. I actually don't know exactly what can and can't be pickles.. not what partialing a function means.. Maybe can you link me to some resources? I still can't understand all the details in your code :) -- http://mail.python.org/mailman/listinfo/python-list

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

2013-08-07 Thread Peter Otten
Joshua Landau wrote: > On 7 August 2013 15:46, Peter Otten <__pete...@web.de> wrote: >> def make_instancemethod(inst, methodname): >> return getattr(inst, methodname) > > This is just getattr -- you can replace the two uses of > make_instancemethod with getattr and delete this ;). D'oh ;)

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

2013-08-07 Thread Joshua Landau
On 7 August 2013 15:46, Peter Otten <__pete...@web.de> wrote: > import copy_reg > import multiprocessing > import new "new" is deprecated from 2.6+; use types.MethodType instead of new.instancemethod. > def make_instancemethod(inst, methodname): > return getattr(inst, methodname) This is jus

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

2013-08-07 Thread Peter Otten
Joshua Landau wrote: > On 7 August 2013 11:10, Luca Cerone wrote: >> I can't try it now, I'll let you know later if it works! >> (Though just by reading I can't really understand what the code does). > > Well, > >>> from multiprocessing import Pool >>> from functools import partial >>> >>> clas

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

2013-08-07 Thread Joshua Landau
On 7 August 2013 11:10, Luca Cerone wrote: > I can't try it now, I'll let you know later if it works! > (Though just by reading I can't really understand what the code does). Well, >> from multiprocessing import Pool >> from functools import partial >> >> class A(object): >> def __init__(sel

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

2013-08-07 Thread Luca Cerone
> > doesn't work neither in Python 2.7, nor 3.2 (by the way I can't use Python > > 3 for my application). > > Are you using Windows? Over here on 3.3 on Linux it does. Not on 2.7 though. No I am using Ubuntu (12.04, 64 bit).. maybe things changed from 3.2 to 3.3? > from multiprocessing import

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

2013-08-07 Thread Joshua Landau
On 7 August 2013 09:33, Luca Cerone wrote: > To correct my example: > > from multiprocessing import Pool > > class A(object): > def __init__(self,x): > self.value = x > def fun(self,x): > return self.value**x > > l = range(100) > p = Pool(4) > op = p.map(A(3).fun, l) > > do

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

2013-08-07 Thread Luca Cerone
Hi Joshua thanks! > I think you might not understand what Chris said. > Currently this does *not* work with Python 2.7 as you suggested it would. > >>> op = map(A.fun,l) Yeah actually that wouldn't work even in Python 3, since value attribute used by fun has not been set. It was my mistake in th

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

2013-08-06 Thread Joshua Landau
On 6 August 2013 20:42, Luca Cerone wrote: > Hi Chris, thanks > >> Do you ever instantiate any A() objects? You're attempting to call an >> >> unbound method without passing it a 'self'. > > I have tried a lot of variations, instantiating the object, creating lambda > functions that use the unbou

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

2013-08-06 Thread Luca Cerone
Hi Chris, thanks > Do you ever instantiate any A() objects? You're attempting to call an > > unbound method without passing it a 'self'. I have tried a lot of variations, instantiating the object, creating lambda functions that use the unbound version of fun (A.fun.__func__) etc etc.. I have pl

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

2013-08-06 Thread Luca Cerone
On Tuesday, 6 August 2013 18:12:26 UTC+1, Luca Cerone wrote: > Hi guys, > > I would like to apply the Pool.map method to a member of a class. > > > > Here is a small example that shows what I would like to do: > > > > from multiprocessing import Pool > > > > class A(object): > >def

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

2013-08-06 Thread Chris Angelico
On Tue, Aug 6, 2013 at 6:12 PM, Luca Cerone 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

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

2013-08-06 Thread Luca Cerone
Hi guys, I would like to apply the Pool.map method to a member of a class. Here is a small example that shows what I would like to do: 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)