[Tutor] killing a thread
Kent Johnson
kent37 at tds.net
Wed Feb 23 06:00:53 CET 2005
Max Noel wrote:
>
> On Feb 22, 2005, at 23:08, Bill Mill wrote:
>
>> If I recall correctly, there is not a direct way. Instead, you're
>> going to want to have your worker thread check a queue it shares with
>> the parent every so often to see if the supervisor thread has sent a
>> "quit" message to it.
>>
>> Peace
>> Bill Mill
>> bill.mill at gmail.com
>
>
> Using "direct" killing methods is not safe, because you never know
> at which point of its execution you terminate the thread. That's a Bad
> Thing(TM).
>
> So instead, the Right Thing is to implement an end() method in the
> object you're using as a thread. That end() method just sets a flag
> (say, isToTerminate) to True.
> Since the thread is running a loop, all you then have to do is have
> it check the isToTerminate flag at the beginning of each loop. If it's
> True, exit the loop (thus terminating the thread as it reaches the end
> of its run() method).
This recipe shows one way to do it:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65448
Kent
>
> -- Max
> maxnoel_fr at yahoo dot fr -- ICQ #85274019
> "Look at you hacker... A pathetic creature of meat and bone, panting and
> sweating as you run through my corridors... How can you challenge a
> perfect, immortal machine?"
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list