On Fri, Sep 6, 2013 at 5:27 AM, Paul Pittlerson <menkomig...@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
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to