Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #13121
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <kushal.kumaran@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:using': 0.04; 'attribute': 0.07; 'admit': 0.09; 'problem:': 0.09; 'exception': 0.12; 'skip:f 30': 0.13; 'def': 0.15; 'skip:" 40': 0.15; 'class:': 0.16; 'deadlock': 0.16; 'deadlock.': 0.16; 'dumps': 0.16; 'lookup': 0.16; 'run(self):': 0.16; 'cc:addr:python-list': 0.16; 'subject:problem': 0.19; 'defined': 0.19; 'received:74.125.82.174': 0.19; 'received:mail- wy0-f174.google.com': 0.19; 'cc:no real name:2**0': 0.20; '(most': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'module,': 0.23; 'traceback': 0.24; 'sender:addr:gmail.com': 0.25; 'function': 0.27; 'skip:_ 20': 0.28; 'skip:" 30': 0.28; 'correct': 0.28; 'import': 0.28; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'seemingly': 0.30; 'class': 0.30; 'yet': 0.32; 'error.': 0.32; "can't": 0.33; 'there': 0.33; 'creates': 0.34; 'test': 0.34; 'last):': 0.34; 'file': 0.36; 'sequence': 0.37; 'subject:skip:m 10': 0.37; 'thread': 0.37; 'using': 0.37; 'run': 0.37; 'received:74.125.82': 0.38; 'forgive': 0.38; 'programming,': 0.38; 'received:google.com': 0.38; 'subject:: ': 0.39; 'manually': 0.39; "there's": 0.39; 'why': 0.39; 'received:74.125': 0.39; 'where': 0.40; 'touch': 0.68; 'skip:\xc2 10': 0.74; 'questions:': 0.84; 'besides,': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=87FOgGbL+ijvCyOpJBNUQKRU+furNQ/+sQ30cN2IcA4=; b=jqTh0u36UnhGNh0+sif1XPxXKfksfYSywAdXTiSZpdM/qwC5O76h1Wj6sdwAxtOqZ3 mfGsYV1yMIr9tOUTBn4SLwr+SSbdbAMHdd5Bea84xudCmPkEeS5In7vvAYoRj8sFRLOv JLbB1DrZaQET4+OlsWrlPWJOcUncR+kPbQl+k= |
| MIME-Version | 1.0 |
| Sender | kushal.kumaran@gmail.com |
| In-Reply-To | <5ccb9d98-f3f8-4f86-b53c-cda4522b40fc@14g2000prv.googlegroups.com> |
| References | <5ccb9d98-f3f8-4f86-b53c-cda4522b40fc@14g2000prv.googlegroups.com> |
| From | Kushal Kumaran <kushal.kumaran+python@gmail.com> |
| Date | Sun, 11 Sep 2011 17:02:18 +0530 |
| X-Google-Sender-Auth | kuOqOE3pHUgD5V4k7GgUa4WzXbw |
| Subject | Re: Deadlock problem using multiprocessing |
| To | 蓝色基因 <bluegene8210@gmail.com> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| 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.981.1315740760.27778.python-list@python.org> (permalink) |
| Lines | 82 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1315740760 news.xs4all.nl 2538 [2001:888:2000:d::a6]:54486 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:13121 |
Show key headers only | View raw
2011/9/11 蓝色基因 <bluegene8210@gmail.com>:
> This is my first touch on the multiprocessing module, and I admit not
> having a deep understanding of parallel programming, forgive me if
> there's any obvious error. This is my test code:
>
> # deadlock.py
>
> import multiprocessing
>
> class MPTask:
> def __init__(self):
> self._tseq= range(10) # task sequence
> self._pool= multiprocessing.Pool(2) # process pool
> def _exe(self, num):
> return num**2
> def run(self):
> result= self._pool.map_async(self._exe, self._tseq)
> return result.get()
>
> result= MPTask().run()
> print(result)
>
> And seemingly it creates a deadlock, I have to manually kill the
> processes in the system monitor, yet it would be OK if the _exe()
> function was defined outside the MPTask class:
>
> # no_deadlock.py
> import multiprocessing
>
> def _exe(num):
> return num**2
>
> class MPTask:
> def __init__(self):
> self._tseq= range(10) # task sequence
> self._pool= multiprocessing.Pool(2) # process pool
> def run(self):
> result= self._pool.map_async(_exe, self._tseq)
> return result.get()
>
> result= MPTask().run()
> print(result)
>
> This would give the correct answer without any deadlock. My questions:
>
> 1. Why is this, where did the deadlock come from?
>
> 2. Besides, is there any material I can refer to about how to avoid
> deadlocks when using multiple processes in the program?
>
I get this exception when I run the first program:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.1/threading.py", line 516, in _bootstrap_inner
self.run()
File "/usr/lib/python3.1/threading.py", line 469, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.1/multiprocessing/pool.py", line 231, in _handle_tasks
put(task)
File "/usr/lib/python3.1/pickle.py", line 1349, in dumps
Pickler(f, protocol, fix_imports=fix_imports).dump(obj)
_pickle.PicklingError: Can't pickle <class 'method'>: attribute lookup
builtins.method failed
There is no deadlock. You are hitting this problem:
http://stackoverflow.com/questions/1816958/cant-pickle-type-instancemethod-when-using-pythons-multiprocessing-pool-map
--
regards,
kushal
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Deadlock problem using multiprocessing 蓝色基因 <bluegene8210@gmail.com> - 2011-09-10 20:54 -0700
Re: Deadlock problem using multiprocessing Kushal Kumaran <kushal.kumaran+python@gmail.com> - 2011-09-11 17:02 +0530
Re: Deadlock problem using multiprocessing Jacky Liu <bluegene8210@gmail.com> - 2011-09-11 08:46 -0700
csiph-web