thread.interrupt_main() behaviour

Ian Kelly ian.g.kelly at
Mon Jul 7 18:30:54 CEST 2014

On Mon, Jul 7, 2014 at 8:41 AM, Piyush Verma <114piyush at> 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:

More information about the Python-list mailing list