killing thread ?
Peter Hansen
peter at engcorp.com
Fri Jan 24 10:31:14 EST 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 ?
What does the code do in the loop? If it calls some other
routines, you could perhaps find a way to dynamically insert
a "raise SystemExit()" into that subroutine, thereby causing
the thread to terminate (assuming it does *not* catch this
exception!) even without changing the code therein.
If you're worried about some kind of denial of service type
thing with code written by someone else: you're out of luck.
Don't use Python. (Or, better yet, get over the worry and just
accept this possibility.)
> I discovered the _Thread__stop() method of threading.Thread object.
> It works. But that seems to be some dirty hack...
As Martin said, it does not work for what you want. It's just
an internal utility function called *when a thread is already
stopping*.
-Peter
More information about the Python-list
mailing list