Currently it is not possible to "kill" thread which is blocked. The rationale for this is handling situations when thread is blocked - e.g. when thread is quering DB when lock occurred on Database. In this case, the main thread has no way how to stop the blocked thread. Killing a thread is also popular question - see .
pthread library and Windows API contains mechanisms for forced termination of threads - see  and . It is also simple to use them using ctypes library but after this action one need to "clean" internal data structures which is bad practice:
# blocked thread handler
t = threading.Thread(name='bar', target=handler)
libpt = ctypes.cdll.LoadLibrary("libpthread.so.0")
# This is nasty cleaning of internal python structures
Is if feasible to add canceling threads to python threading library? I am willing to help creating a patch (at least for linux).
Python-ideas mailing list -- email@example.com
To unsubscribe send an email to firstname.lastname@example.org
Message archived at https://email@example.com/message/ZDERRWIBX7JP5F2VRTTGD4OMCUSMH3QB/
Code of Conduct: http://python.org/psf/codeofconduct/