Cancelling a python thread (revisited...)

sven sven at
Sun Nov 8 13:40:26 CET 2009

On Nov 8, 4:27 am, Carl Banks <pavlovevide... at> wrote:
> It doesn't sound like the thread is communicating with the process
> much.  Therefore:

There is quite a bit of communication -- the computation results are
visulized while they are generated.

> 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.

The second option is a good idea.  Thanks a lot, Carl!

> > 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).

I really don't get that.  If the reason would be that it is too much
work to
implement, then I could accept it.  But saying: We know it is useful,
but we
won't allow to do it, just does not seem reasonable.  Thread
might be generally unsafe, but there are cases when it is safe.  It
should be
up to the user to decide it.  There are many things that do harm if
you don't
use them correctly, and of course it would be a bad idea to remove all
them from Python.

Well, I won't complain too much.  At least some volunteers created
great language and gave it away for free :)

Thanks again for your suggestion.


More information about the Python-list mailing list