Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16654

Re: 70% [* SPAM *] multiprocessing.Queue blocks when sending large object

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'memory.': 0.05; 'subject:object': 0.07; 'subject:when': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'am,': 0.12; 'combined.': 0.16; 'extension,': 0.16; 'justify': 0.16; 'numpy': 0.16; 'pipe,': 0.16; 'solution?': 0.16; 'subject: \n ': 0.16; 'subject:sending': 0.16; 'this:': 0.16; "wouldn't": 0.17; 'wrote:': 0.18; 'memory': 0.21; 'trying': 0.21; 'input': 0.22; '(or': 0.22; 'header:In-Reply- To:1': 0.22; '(usually': 0.23; 'end,': 0.23; 'gil': 0.23; 'produces': 0.23; 'code': 0.25; '(in': 0.26; 'code.': 0.26; "i'm": 0.26; 'tried': 0.27; 'problem': 0.29; 'array': 0.30; 'arrays': 0.30; 'queue': 0.30; 'url:library': 0.31; 'shared': 0.31; "didn't": 0.31; 'skip:( 20': 0.31; 'version': 0.32; 'done,': 0.32; 'header:User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'there': 0.33; 'object': 0.33; 'to:addr:python-list': 0.34; 'copying': 0.35; 'running': 0.35; 'url:python': 0.36; 'post': 0.36; 'received:au': 0.36; 'none': 0.37; 'but': 0.37; 'run': 0.37; 'hello,': 0.37; 'another': 0.37; 'using': 0.38; 'received:org': 0.38; 'put': 0.38; 'url:docs': 0.39; 'url:org': 0.39; 'should': 0.39; 'tasks': 0.39; 'to:addr:python.org': 0.40; 'achieve': 0.61; 'your': 0.61; 'cost': 0.63; 'vary': 0.64; 'believe': 0.65; 'transferring': 0.67; 'benefit': 0.69; 'url:2011': 0.74; '12)': 0.84; 'blocks.': 0.84; 'url:28': 0.84; 'working,': 0.93; 'forever.': 0.95; 'received:110': 0.95; 'subject:SPAM': 0.96
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Lie Ryan <lie.1296@gmail.com>
Subject Re: 70% [* SPAM *] multiprocessing.Queue blocks when sending large object
Date Mon, 05 Dec 2011 23:27:59 +1100
References <23330_1322593803_pATJ9jRv011464_201111292009.44527.dpalao.python@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 110-175-240-90.static.tpgi.com.au
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111124 Thunderbird/8.0
In-Reply-To <23330_1322593803_pATJ9jRv011464_201111292009.44527.dpalao.python@gmail.com>
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.3298.1323088096.27778.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323088096 news.xs4all.nl 6986 [2001:888:2000:d::a6]:49345
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16654

Show key headers only | View raw


On 11/30/2011 06:09 AM, DPalao wrote:
> Hello,
> I'm trying to use multiprocessing to parallelize a code. There is a number of
> tasks (usually 12) that can be run independently. Each task produces a numpy
> array, and at the end, those arrays must be combined.
> I implemented this using Queues (multiprocessing.Queue): one for input and
> another for output.
> But the code blocks. And it must be related to the size of the item I put on
> the Queue: if I put a small array, the code works well; if the array is
> realistically large (in my case if can vary from 160kB to 1MB), the code
> blocks apparently forever.
> I have tried this:
> http://www.bryceboe.com/2011/01/28/the-python-multiprocessing-queue-and-large-
> objects/
> but it didn't work (especifically I put a None sentinel at the end for each
> worker).
>
> Before I change the implementation,
> is there a way to bypass this problem with  multiprocessing.Queue?
> Should I post the code (or a sketchy version of it)?

Transferring data over multiprocessing.Queue involves copying the whole 
object across an inter-process pipe, so you need to have a reasonably 
large workload in the processes to justify the cost of the copying to 
benefit from running the workload in parallel.

You may try to avoid the cost of copying by using shared memory 
(http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes); 
you can use Queue for communicating when a new data comes in or when a 
task is done, but put the large data in shared memory. Be careful not to 
access the data from multiple processes concurrently.

In any case, have you tried a multithreaded solution? numpy is a C 
extension, and I believe it releases the GIL when working, so it 
wouldn't be in your way to achieve parallelism.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: 70% [* SPAM *] multiprocessing.Queue blocks when sending large object Lie Ryan <lie.1296@gmail.com> - 2011-12-05 23:27 +1100

csiph-web