Well you've certainly picked a ticklish area to run into problems. First, forget about the threading aspects for the moment. AFAICT the smallest program which reproduces your problem is:
Code:
import signal
import time
def handler (*args):
pass
signal.signal(signal.SIGBREAK, handler)
time.sleep (10)
Now run that and do a ctrl-break somewhere in that time.sleep. Sure enough...
Traceback (most recent call last):
File "C:\data\temp\sig3.py", line 8, in <module>
time.sleep (10)
IOError: [Errno 4] Interrupted function call
Under the covers, the sleep function is implemented as a WaitForSingleObject call with a timeout. The object being waited on is an anonymous event which is set from a console ctrl handler when one of those interrupts happens (ctrl-c / ctrl-break / shutdown). This makes sure that the (otherwise blocking) sleep can be interrupted.
Bookmarks