On Thu, 25 Nov 2004 15:24:57 +0000 (UTC), Paul Moore
Jp Calderone
writes:
There is no portable way to terminate a thread without its assistance. Python supports no API for this - save one, the ridiculously named "setDaemon" Thread method. Twisted doesn't expose this, nor call it internally, as it can lead to segfaults.
I have hit the same problem recently (C library calls that might hang, and I want to give up and quit regardless in the end). What I came up with was a function deferToDaemonThread, which put the call in a daemon thread (one that the Python main thread will not wait for). It steals a lot of code from deferToThread, but creates a dedicated daemon thread for the call rather than using the thread pool.
IMHO, if a library is _that_ poorly behaved, you ought to be communicating with it over a socket or pipe. Anybody up for writing a 'deferToPythonSubprocess'?