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

Changeset 1590

Show
Ignore:
Timestamp:
01/09/07 12:31:06
Author:
fumanchu
Message:

Fix for #637 (Move signal handlers into Engine class).

Files:

Legend:

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

    r1574 r1590  
    1818    dict where each key is a path, or "relative URL" (for example, "/" or 
    1919    "/path/to/my/page"), and each value is a config dict. Usually, this 
    20     data is provided in the call to cherrypy.tree.mount(root(), config=conf), 
     20    data is provided in the call to tree.mount(root(), config=conf), 
    2121    although you may also use app.merge(conf). 
    2222     
     
    106106        'request.show_tracebacks': False, 
    107107        'log.screen': False, 
     108        }, 
     109    "embedded": { 
     110        # For use with CherryPy embedded in another deployment stack. 
     111        'engine.autoreload_on': False, 
     112        'checker.on': False, 
     113        'tools.log_headers.on': False, 
     114        'request.show_tracebacks': False, 
     115        'log.screen': False, 
     116        'engine.SIGHUP': None, 
     117        'engine.SIGTERM': None, 
    108118        }, 
    109119    "test_suite": { 
  • trunk/cherrypy/_cpengine.py

    r1574 r1590  
    1717STARTED = 1 
    1818 
    19 try: 
    20     if hasattr(signal, "SIGHUP"): 
    21         def SIGHUP(signum=None, frame=None): 
    22             cherrypy.engine.reexec() 
    23         signal.signal(signal.SIGHUP, SIGHUP) 
    24  
    25     if hasattr(signal, "SIGTERM"): 
    26         def SIGTERM(signum=None, frame=None): 
    27             cherrypy.server.stop() 
    28             cherrypy.engine.stop() 
    29         signal.signal(signal.SIGTERM, SIGTERM) 
    30 except ValueError, _signal_exc: 
    31     if _signal_exc.args[0] != "signal only works in main thread": 
    32         raise 
    33  
    3419 
    3520class PerpetualTimer(threading._Timer): 
     
    4429 
    4530class Engine(object): 
    46     """Application interface for (HTTP) servers, plus process controls.""" 
     31    """Interface for (HTTP) applications, plus process controls. 
     32     
     33    Servers and gateways should not instantiate Request objects directly. 
     34    Instead, they should ask an Engine object for a request via the 
     35    Engine.request method. 
     36     
     37    Blocking is completely optional! The Engine's blocking, signal and 
     38    interrupt handling, privilege dropping, and autoreload features are 
     39    not a good idea when driving CherryPy applications from another 
     40    deployment tool (but an Engine is a great deployment tool itself). 
     41    By calling start(blocking=False), you avoid blocking and interrupt- 
     42    handling issues. By setting Engine.SIGHUP and Engine.SIGTERM to None, 
     43    you can completely disable the signal handling (and therefore disable 
     44    autoreloads triggered by SIGHUP). Set Engine.autoreload_on to False 
     45    to disable autoreload entirely. 
     46    """ 
    4747     
    4848    # Configurable attributes 
     
    8181         
    8282        self.state = STARTED 
     83         
     84        self._set_signals() 
    8385         
    8486        freq = self.deadlock_poll_freq 
     
    264266        self.start() 
    265267     
     268     
     269    #                           Signal handling                           # 
     270     
     271    SIGHUP = None 
     272    SIGTERM = None 
     273     
     274    if hasattr(signal, "SIGHUP"): 
     275        def SIGHUP(self, signum=None, frame=None): 
     276            self.reexec() 
     277     
     278    if hasattr(signal, "SIGTERM"): 
     279        def SIGTERM(signum=None, frame=None): 
     280            cherrypy.server.stop() 
     281            self.stop() 
     282     
     283    def _set_signals(self): 
     284        if self.SIGHUP: 
     285            signal.signal(signal.SIGHUP, self.SIGHUP) 
     286        if self.SIGTERM: 
     287            signal.signal(signal.SIGTERM, self.SIGTERM) 
     288     
     289     
     290    #                           Drop privileges                           # 
     291     
    266292    # Special thanks to Gavin Baker: http://antonym.org/node/100. 
    267293    try: 

Hosted by WebFaction

Log in as guest/cpguest to create tickets