Ian Bicking wrote:
> OK, I didn't actually figure out how to kill wedged threads, but I did
> figure out how to (more or less) cleanly exit the process when there's
> wedged threads. The code is in
> http://svn.colorstudy.com/home/ianb/thread_die.py -- mostly it calls
> os._exit, which exits unconditionally, and it has some guards so that
> it tries to exit as cleanly as possible.
> We still don't detect wedged threads, but at least this gives us
> something to do if we did detect those threads. It probably wouldn't
> be hard to add to ThreadedAppServer -- though there's some added
> infrastructure to figure out what to do when you do find a wedged
> thread. E.g., maybe it should just send an email, or it should exit
> (code 3), or do both.
Detecting wedged threads would definitely be a good feature. You'd have to
have a config setting that determined how long a thread must be unresponsive
before it is considered wedged.
One possible response other than exiting the process is to simply "abandon"
the thread and increase the thread pool by one. If the thread is wedged
consuming zero CPU, that's not such a bad option. If it's busy-waiting,
consuming large amounts of CPU, that's not such a great choice, but neither
is exiting the process...
On Windows there's also the Win32 function TerminateThread(), but that is
considered very dangerous and only to be used in extreme circumstances.