Killing threads (was Re: Cancel or timeout a long running regular expression)

Chris Rebert clp2 at
Sat Sep 17 18:27:45 EDT 2011

On Sat, Sep 17, 2011 at 2:35 PM, Chris Angelico <rosuav at> wrote:
> On Sun, Sep 18, 2011 at 5:00 AM, Nobody <nobody at> wrote:
>> The only robust solution is to use a separate process (threads won't
>> suffice, as they don't have a .kill() method).
> Forking a thread to discuss threads.... ahem.
> Why is it that threads can't be killed? Do Python threads correspond
> to OS-provided threads (eg POSIX threads on Linux)? Every OS threading
> library I've seen has some way of killing threads, although I've not
> looked in detail into POSIX threads there (there seem to be two
> options, pthread_kill and pthread_cancel, that could be used, but I've
> not used either). If nothing else, it ought to be possible to
> implement a high level kill simply by setting a flag that the
> interpreter will inspect every few commands, the same way that
> KeyboardInterrupt is checked for.
> Is it just that nobody's implemented it, or is there a good reason for
> avoiding offering this sort of thing?

It's possible that the reason is analogous to why Java has deprecated
its equivalent, Thread.stop():


More information about the Python-list mailing list