Killing threads

Aahz aahz at pythoncraft.com
Mon Apr 6 10:36:00 EDT 2009


In article <685a59cd-9f02-483f-bc59-b55091a181f8 at u9g2000pre.googlegroups.com>,
imageguy  <imageguy1206 at gmail.com> wrote:
>Aahz:
>>
>>For more info, see the slides from my thread tutorial:
>>http://pythoncraft.com/OSCON2001/
>
>Aahz, thanks for this reference and link to your presentation.  At the
>risk of highjacking the OP's question, I am bit confused as to how
>using an Event would cause a deadlock.  You presentation outlines
>Events, but doesn't elaborate on the specifics or usage.

>In threading.Event python 2.5 docs say;
>"This is one of the simplest mechanisms for communication between
>threads: one thread signals an event and other threads wait for it. "
>
>Again, I have limited experience, however, in my reading of the
>threading manual and review examples, Events were specifically design
>to be a thread safe way to communicate a 'state' to running threads ?
>In the OP's example 'do stuff' was open to wide interpretation,
>however, if within the thread's main 'while' loop the tread checks to
>see if the 'keepgoing' Event.isSet(), in what scenario would this
>create deadlock ?

Consider two threads trying to pass information to each other.  You need
two Event objects; unless you are very careful, they can both block on
waiting for each other.  It's easier if Queue is the only construct you
use, it can do everything that the lower-level constructs can do, without
needing to figure out the little gotchas -- and you'll need a Queue
eventually, so just learn that one.  It's all about simplifying.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz



More information about the Python-list mailing list