thread.interrupt_main() behaviour

Ian Kelly ian.g.kelly at gmail.com
Mon Jul 7 12:30:54 EDT 2014


On Mon, Jul 7, 2014 at 8:41 AM, Piyush Verma <114piyush at gmail.com> wrote:
> Thanks Ian for information. There is slightly more I want to do. Consider if
> I want to kill some threads not all, is there a way to do that?

You can't safely interrupt threads.  What you can do is *request* the
thread to terminate by setting a flag on it (perhaps using a
threading.Event object, but an ordinary bool attribute can also be
used), and then having the thread periodically check the state of the
flag and exit gracefully when requested.

For more detail, see:
http://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread-in-python



More information about the Python-list mailing list