killing thread ?

"Martin v. Löwis" martin at
Fri Jan 24 15:59:58 CET 2003

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

You lose. There is no way to cancel a thread, period.

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

What do you mean by "it works"? It does not terminate the thread (just 
read its source code if you don't believe me). If you call it in the 
context of another thread, it has all kinds of funny effects, which is 
why it is a private method (and really spelled __stop).


More information about the Python-list mailing list