Stopping a thread from another one

Peter Hansen peter at engcorp.com
Wed Jun 23 08:29:48 EDT 2004


Antoon Pardon wrote:

> Op 2004-06-23, Chris S. schreef <chrisks at NOSPAMudel.edu>:
>>Incorporating a flag into each thread, which is checked periodically by 
>>the thread to decide whether or not it should end, is the safest way to 
>>terminate threads. However, if you're looking for a preemptive method 
>>that kills a thread unconditionally (whether the thread wants to die or 
>>not) then search this group for 'Kthread', a module created by Connelly 
>>Barnes, which implements a subclass of Thread incorporating this 
>>feature. Note that killing threads preemptively is unsafe and should 
>>only be done with care. This is why it's not part of Python's standard 
>>threading library.
> 
> I thought Python was a language for consenting adults.

The "consulting adults" refrain comes from the idea that two people
should be allowed to engage in whatever behaviour they want,
together, if it's not harming anyone including themselves.  It's
a social thing, you know, keep the government out of the bedroom.

Threads are too difficult, and multithreaded issues too little
understood by most people, to expect that people will not shoot
themselves in the foot with a thread.kill().  Newbies will see
that method and find all manner of creative ways to use it, none
of which will be either required or reliable.

Killing threads is an STD, and in this area Python makes you wear
a condom.

-Peter



More information about the Python-list mailing list