Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'argument': 0.05; '*not*': 0.07; '[1,': 0.09; 'posting.': 0.09; 'subject:method': 0.09; 'that).': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'suggest': 0.14; '2.7': 0.14; 'mostly': 0.14; 'posted': 0.15; 'a()': 0.16; 'chris,': 0.16; 'lambda': 0.16; 'objects?': 0.16; 'said.': 0.16; 'subject:class': 0.16; 'typeerror:': 0.16; 'unbound': 0.16; 'sender:addr:gmail.com': 0.17; 'fix': 0.17; 'wrote:': 0.18; 'bit': 0.19; 'passing': 0.19; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'cc:2**0': 0.24; 'mention': 0.26; 'suggested': 0.26; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'chris': 0.29; 'forgot': 0.30; 'subject:list': 0.30; 'message- id:@mail.gmail.com': 0.30; '"",': 0.31; '3.2': 0.31; 'pickle': 0.31; 'file': 0.32; 'run': 0.32; 'quite': 0.32; '(most': 0.33; 'problem': 0.35; 'subject:with': 0.35; 'advice': 0.35; 'etc': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'version': 0.36; 'explains': 0.36; 'object,': 0.36; 'method': 0.36; 'thanks': 0.36; 'detail': 0.37; 'fact': 0.38; 'recent': 0.39; 'does': 0.39; 'help,': 0.39; 'called': 0.40; 'august': 0.61; "you're": 0.61; 'further': 0.61; 'first': 0.61; 'back': 0.62; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'due': 0.66; '81,': 0.84; 'etc..': 0.84; 'pickled': 0.84; 'played': 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=2IfPYGhGAA2w3s0+CtBsHvOEO74Ddi4qfgGdwBvxeHU=; b=Q1Tl+mPB8itT+gtjj3Ye6dRfF4jXHU4qs8tJdHd1exHvZsSMiNdCUC/KsjFsKAYBRI dRQW0r0JjP+9qQERUcdORGhrHcS8T0cuoyAih0SiDMpCwjGy/haW6KifZsWJmWlpwb5A 8MYIIuSXBxmNepPoB2lqHs0J3Ud1ejUClAFyhI+Z3nTmrtR/Kp37DeIbH3XJQhUK1EUI zy+XnEpbLS85PNja5NV/49iXYEPZCCr4MJgQCHyEDhvRsIjdyR5stQ7VZhKNRx0TcQSo fuTNU+fUJQOG8zUHfP07+5d3kCeqTCJ1cGt8WjEn4fk6prZjVZax10OvZe4pEdFD2fIp KJhA== X-Received: by 10.152.8.228 with SMTP id u4mr704324laa.79.1375858152526; Tue, 06 Aug 2013 23:49:12 -0700 (PDT) MIME-Version: 1.0 Sender: joshua.landau.ws@gmail.com In-Reply-To: <4cff0d5e-33ab-42cd-b6d4-2b4fe235a274@googlegroups.com> References: <96c575da-7601-4023-aa91-e80664f90333@googlegroups.com> <4cff0d5e-33ab-42cd-b6d4-2b4fe235a274@googlegroups.com> From: Joshua Landau Date: Wed, 7 Aug 2013 07:48:32 +0100 X-Google-Sender-Auth: R4no9TL-2PyBzraMGzKuAo8_iB0 Subject: Re: Using Pool map with a method of a class and a list To: Luca Cerone Content-Type: text/plain; charset=UTF-8 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375858161 news.xs4all.nl 15956 [2001:888:2000:d::a6]:47758 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52114 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 unbound version of fun (A.fun.__func__) etc etc.. > I have played around it quite a bit before posting. > > As far as I have understood the problem is due to the fact that Pool pickle the function and copy it in the various pools.. > But since the methods cannot be pickled this fails.. > > The same example I posted won't run in Python 3.2 neither (I am mostly interested in a solution for Python 2.7, sorry I forgot to mention that). > > Thanks in any case for the help, hopefully there will be some other advice in the ML :) 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) Traceback (most recent call last): File "", line 1, in TypeError: unbound method fun() must be called with A instance as first argument (got int instance instead) This, however, does: >>> op = map(A(3).fun,l) >>> op [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683] Chris might have also been confused because once you fix that it works in Python 3. You will find that http://stackoverflow.com/questions/1816958/cant-pickle-type-instancemethod-when-using-pythons-multiprocessing-pool-ma explains the problem in more detail than I understand. I suggest reading it and relaying further questions back to us. Or use Python 3 ;).