How to kill a thread?

John Dohn john.dohn.john at
Fri Jun 6 14:22:38 CEST 2008

On Fri, Jun 6, 2008 at 10:30 PM, John Dohn <john.dohn.john at> wrote:

> Hi there,
> How can I kill a threading.Thread subclass from MainThread?

At the end I did:

        def run(self):
                while True:
                        if exit_event.isSet():
                                # Thread exiting
                                data = q_in.get(timeout = .5)
                        except Queue.Empty:
                        # ... process data

And then in the MainThread I do exit_event.set() and wait for all threads to
exit. It's a pretty awkward solution but works.

BTW Guys, is something like Thread.kill() planned for the future? Or is
there a reason not to have it?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list