threading: how to kill a (possibly blocked) thread?

rturpin at my-deja.com rturpin at my-deja.com
Wed Jan 17 10:44:14 EST 2001


In article <u1yu2vmiq.fsf at ctwd0143.fitlinxx.com>,
  David Bolen <db3l at fitlinxx.com> wrote:
> What you really need to do is ensure that your threads
> can accept an external request to terminate themselves ..

The ideal way to do this is with a timed interrupt that
invokes a function in the thread. The thread would start
by setting this interrupt:

  set_interrupt(8, funcCallBack)

Then, funcCallBack gets invoked every 8 seconds,
interrupting what the thread is doing, and returning
to the interrupted code when the function returns.
Unfortunately, I don't see such a facility in the
library.

> .. The main thread code should then check the event
> object periodically and exit nicely if it is set.

Except for certain kinds of processing, such as FSMs,
this gets REAL ugly REAL fast. It also fails to protect
against the very things for which you want a guard,
i.e., external events that never occur.

Russell



Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list