Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1740

Show
Ignore:
Timestamp:
10/08/07 23:57:03
Author:
fumanchu
Message:

Unregister Ctrl-C handler for Windows console.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/restsrv/win32.py

    r1690 r1740  
    2020    def __init__(self): 
    2121        self.events = {} 
    22         win32api.SetConsoleCtrlHandler(self._console_event) 
     22        result = win32api.SetConsoleCtrlHandler(self._console_event, 1) 
     23        if result == 0: 
     24            self.log('Could not SetConsoleCtrlHandler (error %r)' % 
     25                     win32api.GetLastError()) 
    2326        wspbus.Bus.__init__(self) 
    2427     
    2528    def _console_event(self, event): 
    26         """.""" 
    27         if event in (win32con.CTRL_C_EVENT, 
    28                      win32con.CTRL_BREAK_EVENT, 
     29        """The handler for console control events (like Ctrl-C).""" 
     30        if event in (win32con.CTRL_C_EVENT, win32con.CTRL_LOGOFF_EVENT, 
     31                     win32con.CTRL_BREAK_EVENT, win32con.CTRL_SHUTDOWN_EVENT, 
    2932                     win32con.CTRL_CLOSE_EVENT): 
    3033            self.log('Console event %s: shutting down bus' % event) 
     34             
     35            # Remove this CtrlHandler so repeated Ctrl-C doesn't re-call it. 
     36            try: 
     37                result = win32api.SetConsoleCtrlHandler(self._console_event, 0) 
     38                if result == 0: 
     39                    self.log('Could not remove SetConsoleCtrlHandler (error %r)' % 
     40                             win32api.GetLastError()) 
     41            except ValueError: 
     42                pass 
     43             
    3144            self.stop() 
     45            # 'First to return True stops the calls' 
    3246            return 1 
    3347        return 0 

Hosted by WebFaction

Log in as guest/cpguest to create tickets