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

Changeset 1644

Show
Ignore:
Timestamp:
03/31/07 16:38:17
Author:
fumanchu
Message:

restsrv cosmetics

Files:

Legend:

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

    r1639 r1644  
    5454        # Make a map from signal numbers to names 
    5555        self.signals = {} 
    56         for k in dir(_signal): 
     56        for k, v in vars(_signal): 
    5757            if k.startswith('SIG') and not k.startswith('SIG_'): 
    58                 self.signals[getattr(_signal, k)] = k 
     58                self.signals[v] = k 
    5959         
    6060        self.engine = engine 
     
    7777        # Should we do something with existing signal handlers? 
    7878        # cur = _signal.getsignal(signum) 
    79         _signal.signal(signum, self.handle_signal) 
     79        _signal.signal(signum, self._handle_signal) 
    8080        if callback is not None: 
    8181            self.engine.subscribe(signame, callback) 
    8282     
    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).""" 
    8485        self.engine.publish(self.signals[signum]) 
    8586 
  • trunk/cherrypy/restsrv/restd.py

    r1642 r1644  
    4141 
    4242 
    43 def importer(name): 
    44     # Wrap the given 'name' in a closure. 
    45     def _import(): 
    46         __import__(name, {}, {}, ['']) 
    47     _import.priority = 20 
    48     return _import 
    49  
    50  
    5143def start(opts): 
    5244    if '--project' in opts: 
    5345        # 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) 
    5550     
    5651    if 'win' not in sys.platform: 
  • trunk/cherrypy/restsrv/win32.py

    r1642 r1644  
    1616        base.Engine.__init__(self) 
    1717        self.stop_event = win32event.CreateEvent(None, 0, 0, None) 
    18         win32api.SetConsoleCtrlHandler(self.control_handler
     18        win32api.SetConsoleCtrlHandler(self.console_event
    1919     
    20     def control_handler(self, event): 
     20    def console_event(self, event): 
    2121        if event in (win32con.CTRL_C_EVENT, 
    2222                     win32con.CTRL_BREAK_EVENT, 
    2323                     win32con.CTRL_CLOSE_EVENT): 
    24             self.log('Control event %s: shutting down engine' % event) 
     24            self.log('Console event %s: shutting down engine' % event) 
    2525            self.stop() 
    2626            return 1 
     
    4444            self.state = base.STOPPED 
    4545 
     46 
     47class _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 
     65control_codes = _ControlCodes({'graceful': 138}) 
     66 
     67 
     68def 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]) 
    4675 
    4776 
     
    6796        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) 
    6897        restsrv.engine.stop() 
     98     
     99    def SvcOther(self, control): 
     100        restsrv.engine.publish(control_codes.key_for(control)) 
     101 
    69102 
    70103if __name__ == '__main__': 

Hosted by WebFaction

Log in as guest/cpguest to create tickets