Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52063
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-08-06 12:37 -0700 |
| References | <96c575da-7601-4023-aa91-e80664f90333@googlegroups.com> |
| Message-ID | <b39d3961-9766-45d7-a4af-8db145c27fcd@googlegroups.com> (permalink) |
| Subject | Re: Using Pool map with a method of a class and a list |
| From | Luca Cerone <luca.cerone@gmail.com> |
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 __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) > > > > #using this with the normal map doesn't cause any problem > > > > This fails because it says that the methods can't be pickled. > > (I assume it has something to do with the note in the documentation: "functionality within this package requires that the __main__ module be importable by the children.", which is obscure to me). > > > > I would like to understand two things: why my code fails and when I can expect it to fail? what is a possible workaround? > > > > Thanks a lot in advance to everybody for the help! > > > > Cheers, > > Luca 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 __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) > > > > #using this with the normal map doesn't cause any problem > > > > This fails because it says that the methods can't be pickled. > > (I assume it has something to do with the note in the documentation: "functionality within this package requires that the __main__ module be importable by the children.", which is obscure to me). > > > > I would like to understand two things: why my code fails and when I can expect it to fail? what is a possible workaround? > > > > Thanks a lot in advance to everybody for the help! > > > > Cheers, > > Luca
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Using Pool map with a method of a class and a list Luca Cerone <luca.cerone@gmail.com> - 2013-08-06 10:12 -0700
Re: Using Pool map with a method of a class and a list Chris Angelico <rosuav@gmail.com> - 2013-08-06 18:38 +0100
Re: Using Pool map with a method of a class and a list Luca Cerone <luca.cerone@gmail.com> - 2013-08-06 12:42 -0700
Re: Using Pool map with a method of a class and a list Joshua Landau <joshua@landau.ws> - 2013-08-07 07:48 +0100
Re: Using Pool map with a method of a class and a list Luca Cerone <luca.cerone@gmail.com> - 2013-08-07 01:33 -0700
Re: Using Pool map with a method of a class and a list Joshua Landau <joshua@landau.ws> - 2013-08-07 10:47 +0100
Re: Using Pool map with a method of a class and a list Luca Cerone <luca.cerone@gmail.com> - 2013-08-07 03:10 -0700
Re: Using Pool map with a method of a class and a list Joshua Landau <joshua@landau.ws> - 2013-08-07 12:53 +0100
Re: Using Pool map with a method of a class and a list Luca Cerone <luca.cerone@gmail.com> - 2013-08-07 15:26 -0700
Re: Using Pool map with a method of a class and a list Joshua Landau <joshua@landau.ws> - 2013-08-07 23:49 +0100
Re: Using Pool map with a method of a class and a list Peter Otten <__peter__@web.de> - 2013-08-07 16:46 +0200
Re: Using Pool map with a method of a class and a list Joshua Landau <joshua@landau.ws> - 2013-08-07 16:52 +0100
Re: Using Pool map with a method of a class and a list Peter Otten <__peter__@web.de> - 2013-08-07 18:15 +0200
Re: Using Pool map with a method of a class and a list Luca Cerone <luca.cerone@gmail.com> - 2013-08-07 16:31 -0700
Re: Using Pool map with a method of a class and a list Luca Cerone <luca.cerone@gmail.com> - 2013-08-06 12:37 -0700
csiph-web