我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用win32con.CTRL_C_EVENT。
def handle(self, event): """Handle console control events (like Ctrl-C).""" if event in (win32con.CTRL_C_EVENT, win32con.CTRL_LOGOFF_EVENT, win32con.CTRL_BREAK_EVENT, win32con.CTRL_SHUTDOWN_EVENT, win32con.CTRL_CLOSE_EVENT): self.bus.log('Console event %s: shutting down bus' % event) # Remove self immediately so repeated Ctrl-C doesn't re-call it. try: self.stop() except ValueError: pass self.bus.exit() # 'First to return True stops the calls' return 1 return 0
def _DebugCtrlHandler(evt): if evt in (win32con.CTRL_C_EVENT, win32con.CTRL_BREAK_EVENT): assert g_debugService print "Stopping debug service." g_debugService.SvcStop() return True return False
def _DebugCtrlHandler(evt): if evt in (win32con.CTRL_C_EVENT, win32con.CTRL_BREAK_EVENT): assert g_debugService print("Stopping debug service.") g_debugService.SvcStop() return True return False
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