Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52135
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <joshua.landau.ws@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; '"__main__":': 0.09; '__name__': 0.09; 'deprecated': 0.09; 'items)': 0.09; 'method:': 0.09; 'subject:method': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'a(object):': 0.16; 'b):': 0.16; 'hack,': 0.16; 'lambda': 0.16; 'subject:class': 0.16; 'to:addr:web.de': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'replace': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; 'class': 0.32; 'this.': 0.32; 'skip:_ 10': 0.34; 'subject:with': 0.35; 'received:google.com': 0.35; 'two': 0.37; 'delete': 0.39; 'skip:p 20': 0.39; 'august': 0.61; 'new': 0.61; 'skip:n 10': 0.64; 'otten': 0.84; 'subject:Using': 0.84; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=uQfFiW4ZPHJO76bVsh/aSh/cQM8TI2syU+UKxV4gWSY=; b=O/yVUAbYkqTr5kETwPxdlXHedCMc9g2y66yNvjnOxG9mwPQcngpD5T+4WkAOeon3a+ bwQ5B+yyuDDfwBUgEejhPCaVJATXDiHUlBfxVZ1GGhlqJkUGjTDa0S8FUobg+/ZlngCC 0jXCJypfV6C4TrKOdsl0xMDLpZX4Ih2SRHZ/LnZXY6HSIKhRB1VDn263KlV0aFuLMbsl QlqvuuXAWbc/tBNNqMS2wi6sxlhyLn51Qj6RTTHgyCFYrn2tYKw0oJGX+XdhAlhHq66P yVwwTDPmRUF2/J/QI01IofcbVyRpdaD/xBEt9aQWnUsn0NfL4BwnTc5EmT7a+3lz3fKo 5a0Q== |
| X-Received | by 10.112.33.205 with SMTP id t13mr529424lbi.22.1375890805158; Wed, 07 Aug 2013 08:53:25 -0700 (PDT) |
| MIME-Version | 1.0 |
| Sender | joshua.landau.ws@gmail.com |
| In-Reply-To | <kttmj9$ll4$1@ger.gmane.org> |
| References | <96c575da-7601-4023-aa91-e80664f90333@googlegroups.com> <mailman.268.1375810736.1251.python-list@python.org> <4cff0d5e-33ab-42cd-b6d4-2b4fe235a274@googlegroups.com> <mailman.301.1375858161.1251.python-list@python.org> <021dfe24-af83-4307-856e-441cf35cb93a@googlegroups.com> <mailman.311.1375868873.1251.python-list@python.org> <13807c2e-7f9f-45dd-b36e-4cdc7cde6709@googlegroups.com> <CAN1F8qX5PCVsS-g03BTGYvm3opGNCg1giKC-O9cWADytqJogqw@mail.gmail.com> <kttmj9$ll4$1@ger.gmane.org> |
| From | Joshua Landau <joshua@landau.ws> |
| Date | Wed, 7 Aug 2013 16:52:45 +0100 |
| X-Google-Sender-Auth | RZBa86418HiIkrd2vQen0oTxNZE |
| Subject | Re: Using Pool map with a method of a class and a list |
| To | Peter Otten <__peter__@web.de> |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | python-list <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.316.1375891216.1251.python-list@python.org> (permalink) |
| Lines | 41 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1375891216 news.xs4all.nl 15890 [2001:888:2000:d::a6]:33618 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52135 |
Show key headers only | View raw
On 7 August 2013 15:46, Peter Otten <__peter__@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 just getattr -- you can replace the two uses of
make_instancemethod with getattr and delete this ;).
> def pickle_instancemethod(method):
> return make_instancemethod, (method.im_self, method.im_func.__name__)
>
> copy_reg.pickle(
> new.instancemethod, pickle_instancemethod, make_instancemethod)
>
> class A(object):
> def __init__(self, a):
> self.a = a
> def fun(self, b):
> return self.a**b
>
> if __name__ == "__main__":
> items = range(10)
> pool = multiprocessing.Pool(4)
> print pool.map(A(3).fun, items)
Well that was easy. The Stackoverflow link made that look *hard*. -1
to my hack, +1 to this.
You can do this in one statement:
copy_reg.pickle(
types.MethodType,
lambda method: (getattr, (method.im_self, method.im_func.__name__)),
getattr
)
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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