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


Groups > comp.lang.python > #53743

Re: Multiprocessing / threading confusion

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <marduk@python.net>
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; 'output': 0.05; 'string': 0.09; 'debugger': 0.09; 'output,': 0.09; 'overwrite': 0.09; 'received:internal': 0.09; 'runs': 0.10; 'thread': 0.14; '__del__': 0.16; 'called.': 0.16; 'empty.': 0.16; 'guessing': 0.16; 'helps.': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'momentarily': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:10.202.2.44': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:compute4.internal': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'stuff,': 0.16; 'threads,': 0.16; 'why:': 0.16; 'wrote:': 0.18; '(not': 0.18; 'code.': 0.18; 'trying': 0.19; 'finished': 0.19; 'thu,': 0.19; 'seems': 0.21; 'machine': 0.22; 'print': 0.22; 'paul': 0.24; "haven't": 0.24; 'handling': 0.26; 'second': 0.26; 'least': 0.26; 'code:': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'appear': 0.29; "i'm": 0.30; 'getting': 0.31; 'apparently': 0.31; 'sep': 0.31; 'probably': 0.32; 'stuff': 0.32; 'url:python': 0.33; 'running': 0.33; 'totally': 0.33; 'sense': 0.34; 'problem': 0.35; 'received:66': 0.35; 'basic': 0.35; "can't": 0.35; 'but': 0.35; 'there': 0.35; 'url:org': 0.36; 'received:10': 0.37; 'sometimes': 0.38; 'checks': 0.38; 'process,': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'problems.': 0.60; 'subject: / ': 0.60; 'hope': 0.61; 'url:3': 0.61; 'took': 0.61; 'first': 0.61; 'header:Message- Id:1': 0.63; 'guarantee': 0.63; 'show': 0.63; 'kind': 0.63; 'happen': 0.63; 'different': 0.65; 'started.': 0.68; 'receive': 0.70; 'therefore': 0.72; 'gotten': 0.74; 'atm,': 0.84; 'quits.': 0.84; 'started,': 0.84; 'subject:skip:M 10': 0.84; 'url:datamodel': 0.84; 'url:reference': 0.84; '2013,': 0.91; 'processes,': 0.91
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=ijsaD2slzzfjl7QaUp0USgKZ05Q=; b=h5C 7Q8Mx/zIB2b+Hqp8SFoiGt/5/kWjORKE1OBCxftRhtL21zMWkyoZ8rnCINjUiNWK HwlrceaKWjF9oIv5wp+LVmT+B2T2LLlGfRBz1UPdjTJXW55ayC+aKBy0KEYIuutK XkSYuYyXHa0+mWtwxC67iMUXMdHs/SJf3LQdg16M=
X-Sasl-Enc aE6DsGjmX2juZy0DcgzQ37hkpvQH4ruYUkOrJNiIZAHd 1378420119
From "marduk@python.net" <marduk@python.net>
To python-list@python.org
MIME-Version 1.0
Content-Transfer-Encoding 7bit
Content-Type text/plain
X-Mailer MessagingEngine.com Webmail Interface - ajax-ed2f0e98
In-Reply-To <ca7ea9d1-4dad-4a30-97b2-ad8536a1860b@googlegroups.com>
References <ca7ea9d1-4dad-4a30-97b2-ad8536a1860b@googlegroups.com>
Subject Re: Multiprocessing / threading confusion
Date Thu, 05 Sep 2013 18:28:39 -0400
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.107.1378420122.5461.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1378420122 news.xs4all.nl 15997 [2001:888:2000:d::a6]:42093
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53743

Show key headers only | View raw



On Thu, Sep 5, 2013, at 03:27 PM, Paul Pittlerson wrote:
> I'm trying to understand data handling using multiprocessing and
> threading, haven't gotten very far without running into problems. This is
> my code:

[snip (not sure why you are using multiprocessing and threading at the
same time]


> What I expect to happen is the Debugger object will receive one string at
> a time, and read it from the queue. But that's not what I see the the
> output, the "started worker" stuff seems to print for every process, but
> "ticked" and "exited" will show up in unpredictable ways, I'm guessing
> they overwrite each other and therefore will not always appear in the
> output.
> 
> So I'm looking for help in trying to make sense of this kind of stuff, I
> thought this was the basic functionality that Queue() would take care of
> unless there is some other problem in my code.

My output is probably totally different than your output.  I only get
the processes starting.  Here's why:  This stuff all runs
asynchronously.  When you start the "Debugger" thread.. I see you put a
sleep() in it, but that guarantees nothing.  At least on my machine
which is somewhat loaded ATM, by the time the Processes are started, the
Debugger thread has already finished (because of the check to see if the
queue was empty).  Apparently it is took longer than 1 second from the
time the Debugger was started and the first Process was started.
Likewise, what you are getting is probably a case where the queue is
momentarily empty by the time the debugger loop gets ahold of the queue
lock and checks to see if it's empty.  Therefore the Debugger quits. 
Also because of the asynchronicity of processes, threads, you can not
guarantee the order that the processes will get the opportunity to put()
into the queue. 

Also you can't (and shouldn't) depend on the time that __del__ gets
called.  It can get called at any time, in any order and sometimes not
at all.*

Hope this helps.

*
http://docs.python.org/3/reference/datamodel.html?highlight=__del__#object.__del__

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


Thread

Multiprocessing / threading confusion Paul Pittlerson <menkomigen6@gmail.com> - 2013-09-05 12:27 -0700
  Re: Multiprocessing / threading confusion "marduk@python.net" <marduk@python.net> - 2013-09-05 18:28 -0400
    Re: Multiprocessing / threading confusion Paul Pittlerson <menkomigen6@gmail.com> - 2013-09-05 16:34 -0700
      Re: Multiprocessing / threading confusion Chris Angelico <rosuav@gmail.com> - 2013-09-06 13:00 +1000
  Re: Multiprocessing / threading confusion Chris Angelico <rosuav@gmail.com> - 2013-09-06 08:46 +1000
    Re: Multiprocessing / threading confusion Paul Pittlerson <menkomigen6@gmail.com> - 2013-09-05 17:03 -0700
      Re: Multiprocessing / threading confusion Piet van Oostrum <piet@vanoostrum.org> - 2013-09-05 23:54 -0400
        Re: Multiprocessing / threading confusion Piet van Oostrum <piet@vanoostrum.org> - 2013-09-06 00:28 -0400
  Re: Multiprocessing / threading confusion Paul Pittlerson <menkomigen6@gmail.com> - 2013-09-06 11:27 -0700
    Re: Multiprocessing / threading confusion Skip Montanaro <skip@pobox.com> - 2013-09-06 13:53 -0500
    Re: Multiprocessing / threading confusion Dave Angel <davea@davea.name> - 2013-09-06 20:34 +0000
    Re: Multiprocessing / threading confusion Piet van Oostrum <piet@vanoostrum.org> - 2013-09-06 17:15 -0400

csiph-web