[ANN] TortoiseHg-0.3

David Ripton dripton at ripton.net
Sun Feb 3 13:13:46 CST 2008


On 2008.02.02 22:54:06 -0600, Steve Borho wrote:
> On Sat, 2008-02-02 at 20:07 -0800, Brad Schick wrote:
> > -Would be nice to have a way to cancel running datamining searches. I 
> > ran two regexp searches that consumed 100% of the cpu and didn't end 
> > until I killed python (which I now can't repro).
> 
> Anyone know how to stop a Python thread?

There's no built-in, safe, easy way.

You can write your threads such that they suicide upon command:

class KillableThread(threading.Thread):
    time_to_die = False

    def please_die(self):
        self.time_to_die = True

    def run(self):
        while True:
            if self.time_to_die:
                return
            # Do a small amount of work here, without blocking too long

But if you're calling a blocking library without timeouts that's outside
your control, then that doesn't really work.

One (cool, but possibly brittle or non-portable) option is to mess
around inside Python's threading internals like:
http://sebulba.wikispaces.com/recipe+thread2

Another option is to call such libraries from within a subprocess.
Killing processes is portable.

-- 
David Ripton    dripton at ripton.net


More information about the Mercurial mailing list