def consoleCtrlHandler(self, ctrlType):
"""Called by Windows on a new thread whenever a console control
event is raised."""
logger.debug("Windows control event %d" % ctrlType)
sig = None
if ctrlType == win32con.CTRL_C_EVENT:
# user pressed Ctrl+C or someone did GenerateConsoleCtrlEvent
sig = signal.SIGINT
elif ctrlType == win32con.CTRL_BREAK_EVENT:
sig = signal.SIGTERM
elif ctrlType == win32con.CTRL_CLOSE_EVENT:
# Console is about to die.
# CTRL_CLOSE_EVENT gives us 5 seconds before displaying
# the "End process" dialog - so treat as 'fast'
sig = signal.SIGTERM
elif ctrlType in (win32con.CTRL_LOGOFF_EVENT,
win32con.CTRL_SHUTDOWN_EVENT):
# MSDN says:
# "Note that this signal is received only by services.
# Interactive applications are terminated at logoff, so
# they are not present when the system sends this signal."
# We can therefore ignore it (our service framework
# manages shutdown in this case)
pass
else:
logger.info("Unexpected windows control event %d" % ctrlType)
# Call the signal handler - we could also do it asynchronously
# by setting the relevant event, but we need it synchronous so
# that we don't wake the select loop until after the shutdown
# flags have been set.
result = 0
if sig is not None and sig in self.registry:
self.signalHandler(sig, None)
result = 1 # don't call other handlers.
return result
评论列表
文章目录