From: Richard Lamboj on

Hello,

which Method is better to kill a Thread? Using Thread Events, or a raising a
Exception? Maybe someone has a small example for me?

Kind Regards,

Richi
From: Gabriel Genellina on
En Thu, 28 Jan 2010 10:25:30 -0300, Richard Lamboj
<richard.lamboj(a)bilcom.at> escribi�:

> which Method is better to kill a Thread? Using Thread Events, or a
> raising a
> Exception? Maybe someone has a small example for me?

The best way is simply NOT to do that. You don't kill a thread, you ask it
to commit suicide. There is no reliable way to forcefully shut down
another thread.

The thread must periodically check some value (perhaps an Event object; in
simple cases any variable will do) and (cleanly) exit when asked to.

Threads that run pure Python code may be interrupted using the API call
PyThreadState_SetAsyncExc; look for a recipe using ctypes to call it from
Python.

--
Gabriel Genellina