Killing threads

Joshua Marshall jmarshal at mathworks.com
Fri Mar 16 14:47:23 EST 2001


Steve Purcell <stephen_purcell at yahoo.com> wrote:
> 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

Yes, thread cancellation can get you in trouble.  But I'd still like
to have this option.  Specifically, I'd like to be able to raise a
particular exception in a given thread.



More information about the Python-list mailing list