Changeset 1644
- Timestamp:
- 03/31/07 16:38:17
- Files:
-
- trunk/cherrypy/restsrv/plugins.py (modified) (2 diffs)
- trunk/cherrypy/restsrv/restd.py (modified) (1 diff)
- trunk/cherrypy/restsrv/win32.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/restsrv/plugins.py
r1639 r1644 54 54 # Make a map from signal numbers to names 55 55 self.signals = {} 56 for k in dir(_signal):56 for k, v in vars(_signal): 57 57 if k.startswith('SIG') and not k.startswith('SIG_'): 58 self.signals[ getattr(_signal, k)] = k58 self.signals[v] = k 59 59 60 60 self.engine = engine … … 77 77 # Should we do something with existing signal handlers? 78 78 # cur = _signal.getsignal(signum) 79 _signal.signal(signum, self. handle_signal)79 _signal.signal(signum, self._handle_signal) 80 80 if callback is not None: 81 81 self.engine.subscribe(signame, callback) 82 82 83 def handle_signal(self, signum=None, frame=None): 83 def _handle_signal(self, signum=None, frame=None): 84 """Python signal handler (self.set_handler registers it for you).""" 84 85 self.engine.publish(self.signals[signum]) 85 86 trunk/cherrypy/restsrv/restd.py
r1642 r1644 41 41 42 42 43 def importer(name):44 # Wrap the given 'name' in a closure.45 def _import():46 __import__(name, {}, {}, [''])47 _import.priority = 2048 return _import49 50 51 43 def start(opts): 52 44 if '--project' in opts: 53 45 # delay import until after daemonize has a chance to run 54 restsrv.engine.subscribe('start', importer(opts['--project'])) 46 def _import(): 47 __import__(opts['--project'], {}, {}, ['']) 48 _import.priority = 20 49 restsrv.engine.subscribe('start', _import) 55 50 56 51 if 'win' not in sys.platform: trunk/cherrypy/restsrv/win32.py
r1642 r1644 16 16 base.Engine.__init__(self) 17 17 self.stop_event = win32event.CreateEvent(None, 0, 0, None) 18 win32api.SetConsoleCtrlHandler(self.con trol_handler)18 win32api.SetConsoleCtrlHandler(self.console_event) 19 19 20 def con trol_handler(self, event):20 def console_event(self, event): 21 21 if event in (win32con.CTRL_C_EVENT, 22 22 win32con.CTRL_BREAK_EVENT, 23 23 win32con.CTRL_CLOSE_EVENT): 24 self.log('Con trolevent %s: shutting down engine' % event)24 self.log('Console event %s: shutting down engine' % event) 25 25 self.stop() 26 26 return 1 … … 44 44 self.state = base.STOPPED 45 45 46 47 class _ControlCodes(dict): 48 """Control codes used to "signal" a service via ControlService. 49 50 User-defined control codes are in the range 128-255. We generally use 51 the standard Python value for the Linux signal and add 128. Example: 52 53 >>> signal.SIGUSR1 54 10 55 control_codes['graceful'] = 128 + 10 56 """ 57 58 def key_for(self, obj): 59 """For the given value, return its corresponding key.""" 60 for key, val in self.iteritems(): 61 if val is obj: 62 return key 63 raise ValueError("The given object could not be found: %r" % obj) 64 65 control_codes = _ControlCodes({'graceful': 138}) 66 67 68 def signal_child(service, command): 69 if command == 'stop': 70 win32serviceutil.StopService(service) 71 elif command == 'restart': 72 win32serviceutil.RestartService(service) 73 else: 74 win32serviceutil.ControlService(service, control_codes[command]) 46 75 47 76 … … 67 96 self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) 68 97 restsrv.engine.stop() 98 99 def SvcOther(self, control): 100 restsrv.engine.publish(control_codes.key_for(control)) 101 69 102 70 103 if __name__ == '__main__':

