Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25544
| Path | csiph.com!usenet.pasdenom.info!goblin1!goblin2!goblin.stu.neva.ru!feeder3.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.130.MISMATCH!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <panisson@di.unito.it> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'python': 0.09; 'callback': 0.09; 'issue?': 0.09; 'overridden': 0.09; 'subject:skip:m 10': 0.09; 'def': 0.10; '2.7.3': 0.16; 'andr\xe9': 0.16; 'etc....': 0.16; 'range(20):': 0.16; 'result:': 0.16; 'stumbling': 0.16; 'wrote:': 0.17; 'all,': 0.21; 'import': 0.21; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'executing': 0.27; 'behaviour': 0.29; "i'm": 0.29; 'skip:- 10': 0.32; 'print': 0.32; 'ubuntu': 0.33; 'to:addr:python-list': 0.33; 'skip:- 20': 0.34; 'pm,': 0.35; 'subject:with': 0.36; 'being': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'time,': 0.62; 'strange': 0.62; 'behavior': 0.64; 'taking': 0.65; 'received:130': 0.75; '11:44': 0.84 |
| X-MailScanner-From | panisson@di.unito.it |
| X-SpamCheck | not spam, SpamAssassin (not cached, score=-102.448, required 3, autolearn=not spam, AUTHENTICATEDUSER -100.00, AWL -0.64, BAYES_00 -1.90, RCVD_IN_DNSWL_LOW -0.70, RDNS_NONE 0.79, SPF_PASS -0.00) |
| X-AntiVirus | Email Clean |
| X-dipinfo-MailScanner-ID | q6HNHKfH013273 |
| X-dipinfo-MailScanner-Information | Please contact Department of Computer Science technical staff for more information |
| X-DKIM | OpenDKIM Filter v2.4.1 pianeta.di.unito.it q6HNHKfH013273 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/simple; d=di.unito.it; s=dipinfo2011; t=1342567040; bh=gI7zRAXkBiXPuIUzL0zszgpl/GPTqRaPHim2dAAgSRI=; h=Message-ID:Date:From:MIME-Version:To:Subject:References: In-Reply-To:Content-Type; b=aScy4UHrNfwEfnS/VtxJOC/ESb1LxLaJFAhMZZfy8ML9Ju+RRLZa8xx0EoCuEhm/o 5a8SHUr/AUzj1ampIWm26ujxs2OWfPqm8xIDIdzTQXF9zMvl8c9AVAPy4pNgIitIsr rvETvEvF8R2FEYkaYnDMUGGZTQXRTtWdIQgZy4Z4= |
| Date | Wed, 18 Jul 2012 01:17:20 +0200 |
| From | André Panisson <panisson@di.unito.it> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: multiprocessing: apply_async with different callbacks |
| References | <5005DCBB.4080205@di.unito.it> |
| In-Reply-To | <5005DCBB.4080205@di.unito.it> |
| Content-Type | multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; boundary="------------ms080200040800020401090009" |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| 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.2252.1342567044.4697.python-list@python.org> (permalink) |
| Lines | 145 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1342567044 news.xs4all.nl 6949 [2001:888:2000:d::a6]:39863 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:25544 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On 07/17/2012 11:44 PM, André Panisson wrote:
> Hi all,
>
> I'm having a strange behavior when executing the following script:
> ---------------------------
> import multiprocessing
>
> def f(i):
> return i
>
> p = multiprocessing.Pool()
> for i in range(20):
> def c(r):
> print r, i
> p.apply_async(f, (i,) , callback=c)
> p.close()
> p.join()
> ---------------------------
>
> Result:
> 0 6
> 1 11
> 2 13
> 3 15
> 4 15
> 5 19
> etc....
>
> It seems that the callbacks of all submitted tasks are being
> overridden with the last callback submitted by apply_async.
> Is this the right behaviour or I am stumbling in some issue? I'm using
> Python 2.7.3 @ Ubuntu 12.04
>
> Regards,
Sorry for taking the time, I just found the solution:
-------------------
import multiprocessing
def f(i):
return i
def cfactory(i):
def c(r):
print r, i
return c
p = multiprocessing.Pool()
for i in range(20):
p.apply_async(f, (i,) , callback=cfactory(i))
p.close()
p.join()
------------------
Regards,
André
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: multiprocessing: apply_async with different callbacks André Panisson <panisson@di.unito.it> - 2012-07-18 01:17 +0200
csiph-web