Cancelling a python thread (revisited...)

Antoine Pitrou solipsis at
Sun Nov 8 14:52:17 CET 2009

Le Sun, 08 Nov 2009 04:40:26 -0800, sven a écrit :
> I really don't get that.  If the reason would be that it is too much
> work to
> implement, then I could accept it.

It would probably be a lot of work and even then it would still be unsafe.

Read for example:

« TerminateThread is a dangerous function that should only be used in the 
most extreme cases. You should call TerminateThread only if you know 
exactly what the target thread is doing, and you control all of the code 
that the target thread could possibly be running at the time of the 
termination. For example, TerminateThread can result in the following 

    * If the target thread owns a critical section, the critical section 
will not be released.
    * If the target thread is allocating memory from the heap, the heap 
lock will not be released.
    * If the target thread is executing certain kernel32 calls when it is 
terminated, the kernel32 state for the thread's process could be 
    * If the target thread is manipulating the global state of a shared 
DLL, the state of the DLL could be destroyed, affecting other users of 
the DLL. »

More information about the Python-list mailing list