How to kill a thread from another thread ?

Robert Amesz rcameszREMOVETHIS at dds.removethistoo.nl
Fri Nov 10 21:12:52 EST 2000


Aahz Maruch wrote:

>In article <3A0A6715.35C19F47 at ina.fr>, Richard Gruet 
><rgruet at ina.fr> wrote: 
>>
>>Does someone know how to kill a Python thread from another Python
>>thread (in the same process) ?
>
>You don't.  You need to set up each of your threads so that they
>look for some kind of signal to kill themselves (which means
>returning).  It has been argued that the ability to kill threads is
>necessary for server applications, but I haven't seen any powerful
>arguments in favor of that. 

How about doing blocking I/O in a thread? If something goes wrong the 
thread might block forever. Anticipating the response: "So don't do 
blocking I/O", I'd like to add that you may not have that option, 
because the blocking call could be in another module which you need to 
use but didn't write yourself.

If Python uses non-blocking I/O internally, *and* it had the ability to 
raise exceptions in another thread you would have a very powerful 
mechanism to kill threads and still have a thread clean up after itself 
(which is, I think, the most powerful argument against having threads 
kill each other).


Robert Amesz



More information about the Python-list mailing list