Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53744
| References | <ca7ea9d1-4dad-4a30-97b2-ad8536a1860b@googlegroups.com> |
|---|---|
| Date | 2013-09-06 08:46 +1000 |
| Subject | Re: Multiprocessing / threading confusion |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.108.1378421209.5461.python-list@python.org> (permalink) |
On Fri, Sep 6, 2013 at 5:27 AM, Paul Pittlerson <menkomigen6@gmail.com> 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: > > > 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. The first thing I notice is that your Debugger will quit as soon as its one-secondly poll results in no data. This may or may not be a problem for your code, but I'd classify it as code smell at best. Is your goal here to make sure Debugger doesn't stop your process from exiting? If so, a simpler and safer solution is to make it a daemon thread. The other thing I see here is your use of __del__ to print your exit message. I don't know if Thread objects are involved in reference loops, but if they are, __del__ (probably) won't be called immediately on thread termination. Your subprocesses are a little odd; they spin off another thread, then halt the first thread. Why not simply do the work in the first thread? You then treat the thread's __del__ method as the process's death, which isn't strictly true, but probably close enough. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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