How to kill a thread?

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


On Fri, Jun 6, 2008 at 10:30 PM, John Dohn <john.dohn.john at gmail.com> 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
                                return
                        try:
                                data = q_in.get(timeout = .5)
                        except Queue.Empty:
                                continue
                        # ... 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?

Thanks

JD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080607/03d2e724/attachment.html>


More information about the Python-list mailing list