Killing threads

Steve Purcell stephen_purcell at yahoo.com
Fri Mar 16 13:27:39 EST 2001


costas at meezon.com wrote:
> I have th program below. How does one go about kill a thread once
> started? Why is there no method for killing threads? I thought del
> would do it but obviously it doesn't.

Thread cancellation is generally considered a bad thing. If I'm not mistaken,
the argument against allowing thread cancellation is concerned with
correctly releasing locks shared between threads.  (I can trust Mr. Martelli
to set me straight on this if I'm wrong :-)

You should think about using a synchronisation mechanism
(threading.Condition, threading.Semaphore, Queue.Queue) so that the worker
thread can exit itself when told to do so by the main thread changing the
synchronising object.

-Steve

-- 
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo




More information about the Python-list mailing list