Cancelling a python thread (revisited...)

Carl Banks pavlovevidence at gmail.com
Sat Nov 7 22:27:52 EST 2009


On Nov 7, 6:04 pm, Sven Marnach <s... at pantoffel-wg.de> wrote:
> So do I really have to refactor my C library just because Python
> Thread objects lack a cancel method?  Is there really no other way?

It doesn't sound like the thread is communicating with the process
much.  Therefore:

1. Run the C code in a separate process, or
2. Create the thread from a C extension, maybe even straight from
ctypes, and kill it from C or ctypes.


> And why on earth doesn't that cancel method exist? There *are* good
> reasons to cancel a thread, just google for "terminate a Python
> thread" for tons of examples.

Arguing that there are good reasons to allow killing threads isn't
going to get you very far.  The language developers already know
killing a thread is useful, yet the disallowed it anyway.  The
drawbacks were judged too severe (it makes enforcing invariants pretty
much impossible).


Carl Banks



More information about the Python-list mailing list