How to kill a thread?

Rhamphoryncus rhamph at gmail.com
Sat Jun 7 02:32:32 EDT 2008


On Jun 6, 12:44 pm, The Pythonista <n... at this.time> wrote:
> It's always been my understanding that you can't forcibly kill a thread
> in Python (at least not in a portable way).  The best you can do is
> politely ask it to die, IIRC.

Inherently, the best you can do in most languages is ask them politely
to die.  Otherwise you'll leave locks and various other datastructures
in an inconvenient state, which is too complex to handle correctly.
The exception is certain functional languages, which aren't capable of
having threads and complex state in the same sense.

However, you could go quite far with a standardized mechanism of
politely asking threads to die.  For instance, all blocking I/O
functions could be made to support it.  This is how cancellation works
in python-safethread.



More information about the Python-list mailing list