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


Groups > comp.lang.python > #9567

Re: Python threading/multiprocessing issue.

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <missive@hotmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.038
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'subject:Python': 0.06; 'python': 0.08; 'attribute': 0.09; 'output': 0.11; '"don\'t': 0.16; ':o)': 0.16; 'doing:': 0.16; 'thread.': 0.16; 'method.': 0.16; 'seems': 0.20; 'code.': 0.22; 'runs': 0.23; 'code': 0.24; 'point,': 0.25; 'says': 0.25; "i'm": 0.27; 'objects': 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; '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; '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; 'your': 0.60; 'here': 0.66; 'exact': 0.69; 'relevant': 0.69; 'loses': 0.84; 'parts,': 0.84; 'seen.': 0.84
X-Originating-IP [70.101.97.52]
From Lee Harr <missive@hotmail.com>
To <python-list@python.org>
Subject Re: Python threading/multiprocessing issue.
Date Sat, 16 Jul 2011 01:25:14 +0430
Importance Normal
Content-Type text/plain; charset="windows-1256"
Content-Transfer-Encoding 8bit
MIME-Version 1.0
X-OriginalArrivalTime 15 Jul 2011 20:55:14.0353 (UTC) FILETIME=[7E9C4210:01CC4331]
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.1074.1310763387.1164.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1310763387 news.xs4all.nl 23855 [2001:888:2000:d::a6]:49094
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:9567

Show key headers only | View raw


> 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. Lee Harr <missive@hotmail.com> - 2011-07-16 01:25 +0430

csiph-web