I have a function that occasionally hangs.
Normally I would set an alarm, but I'm in Windows and it's unavailable.
Is there a simple way around this, or should I just create a thread that calls time.sleep()
?
The most robust solution is to use a subprocess, then kill that subprocess. Python2.6 adds .kill() to subprocess.Popen().
I don't think your threading approach works as you expect. Deleting your reference to the Thread object won't kill the thread. Instead, you'd need to set an attribute that the thread checks once it wakes up.