How to kill a thread from another thread ?

Richard Gruet rgruet at ina.fr
Thu Nov 9 11:40:50 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.

Actually, I'm using a thread to execute a function call asynchronously, to avoid
getting stuck is something goes wrong. To execute the call, I create a thread and
delegate the actual function call to it. Then, in the main thread, I wait for the
end of the thread (ie the return of the function called) with a timeout (using a
join).
The problem is that if a timeout occurs because the function doesn't return, I
have no way to kill the thread and sometimes it appears to prevent the program to
exit correctly (it hangs because there is still living threads).

Richard





More information about the Python-list mailing list