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


Groups > comp.lang.python > #9571

Re: Python threading/multiprocessing issue.

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <brandon.harris@mail.reelfx.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'python': 0.08; 'attribute': 0.09; 'output': 0.11; 'wrote:': 0.15; '"don\'t': 0.16; ':o)': 0.16; 'both.': 0.16; 'brandon': 0.16; 'doing:': 0.16; 'see.': 0.16; 'thread.': 0.16; 'threading': 0.16; 'method.': 0.16; 'pm,': 0.16; 'possibly': 0.16; 'example.': 0.19; 'seems': 0.20; 'pointed': 0.22; 'header:In-Reply-To:1': 0.22; 'code.': 0.22; 'runs': 0.23; 'code': 0.24; 'point,': 0.25; 'says': 0.25; 'fine': 0.26; "i'm": 0.27; 'objects': 0.28; 'lee': 0.28; 'process,': 0.28; 'problem': 0.29; 'code,': 0.29; 'object': 0.30; 'example': 0.30; 'basically,': 0.30; 'get.': 0.30; 'modifying': 0.30; 'queue': 0.30; 'use?': 0.30; 'separate': 0.31; 'url:library': 0.31; 'changes': 0.31; 'words,': 0.32; 'it.': 0.33; "i've": 0.33; 'to:addr:python-list': 0.34; 'header:User-Agent:1': 0.34; 'there': 0.34; 'replacement': 0.35; 'running': 0.35; 'hold': 0.36; 'subject:/': 0.36; 'page': 0.36; 'url:python': 0.37; 'issue': 0.37; 'thread': 0.37; 'but': 0.37; 'could': 0.37; 'using': 0.37; 'url:org': 0.38; 'subject:: ': 0.38; 'think': 0.38; 'hoping': 0.38; 'run': 0.39; 'url:docs': 0.39; 'help': 0.39; 'allows': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.40; 'sense': 0.40; 'kind': 0.60; 'your': 0.60; 'designed': 0.63; 'here': 0.66; 'exact': 0.69; 'relevant': 0.69; 'loses': 0.84; 'parts,': 0.84; 'seen.': 0.84
Date Fri, 15 Jul 2011 16:24:14 -0500
From Brandon Harris <brandon.harris@reelfx.com>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.38.b3pre.fc13 Lightning/1.0b3pre Thunderbird/3.1.9
MIME-Version 1.0
To python-list@python.org
Subject Re: Python threading/multiprocessing issue.
References <SNT106-W28C92B220F97ABFE97E73CB1490@phx.gbl>
In-Reply-To <SNT106-W28C92B220F97ABFE97E73CB1490@phx.gbl>
Content-Type text/plain; charset=windows-1256; format=flowed
Content-Transfer-Encoding 7bit
X-OriginalArrivalTime 15 Jul 2011 21:23:40.0227 (UTC) FILETIME=[7763F930:01CC4335]
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.1078.1310765056.1164.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1310765056 news.xs4all.nl 23910 [2001:888:2000:d::a6]:43425
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:9571

Show key headers only | View raw


I see. Well I was hoping to see the same result in the multiprocessing 
example as using the threading example. What you pointed out makes sense 
though, but what I don't understand is how modifying the queue in the 
example works fine in both. Possibly it was designed for that kind of use?

Brandon L. Harris


On 07/15/2011 03:55 PM, Lee Harr wrote:
>> I'm working on a tool that runs a number of process is separate thread.
>> I've, up to this point, been using threading.Thread, but from what I
>> read multiprocess will allow multiple processors to be used
>>    From the python docs on multiprocessing.
>> <Due to this, the multiprocessing module allows the programmer to fully
>>           leverage multiple processors on a given machine.>
>>
>> I have run into an issue when modifying the thread object from the run
>> method. Threading.thread allows me to change an attribute in the run
>> method and it hold while multiprocessing.Process loses it.
>
> I am not a multiprocessing expert, but I think the problem you
> are having is that Process is running your code in a separate
> process, so there is no way you could see those object changes
> in your main line code.
>
> In other words, Process is not an exact replacement for Thread.
> If you need to communicate between the different parts, you
> would want to use the abstractions provided by Queue or Pipe.
>
>
> Keep reading down the multiprocessing page in the docs until
> you get to "Exchanging objects between processes":
> http://docs.python.org/library/multiprocessing.html#exchanging-objects-between-processes
>
>
> "Sharing state between processes" seems like it will be especially
> relevant to what you are doing:
> http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes
>
> Basically, it says "don't do that"  :o)
>
>
>> Here is an example illustrating the inconsistency that I've seen.
> One thing that would help here is a sample of what output
> you get from your code, and what you were hoping to get.
>
>   		 	   		

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


Thread

Re: Python threading/multiprocessing issue. Brandon Harris <brandon.harris@reelfx.com> - 2011-07-15 16:24 -0500

csiph-web