killing thread ?

Uwe Schmitt uwe.schmitt at procoders.net
Fri Jan 24 15:12:55 CET 2003


Laura Creighton <lac at strakt.com> wrote:
>> 
>> Hi,
>> 
>> AFAIK there is no method in the threading module to kill a thread.
>> Each thread has to terminate itself by watching status variables.
>> But: what happens if I start a thread, and when I want to kill
>> this thread, I delete all references to the according Thread object,
>> and call the garbage collector. 
>> Will this work ??

> No.  You cannot stand outside your application and kill a thread.
> Instead you have to arrange for your thread to receive the message
> to go commit suicide (and then your thread has to know how to do
> that).  If your threads are already communicating by Queues, sticking
> a 'do_die' in there is often cleanest.  

> <snip> 

But what if I want to end a thread which hangs because
it uses 'exec' on some code which loops forever ?

I discovered the _Thread__stop() method of threading.Thread object.
It works. But that seems to be some dirty hack...

Greetings, Uwe


-- 
Dr. rer. nat. Uwe Schmitt      Computer science is no more about Computers,
uwe.schmitt at num.uni-sb.de      than astronomy is about telescopes. (Dijkstra)
http://www.procoders.net           




More information about the Python-list mailing list