[Tutor] killing a thread

Max Noel maxnoel_fr at yahoo.fr
Wed Feb 23 03:37:41 CET 2005


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).

-- 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?"



More information about the Tutor mailing list