Package cherrypy :: Package process :: Module plugins :: Class SignalHandler
[hide private]
[frames] | no frames]

Class SignalHandler

source code

object --+
         |
        SignalHandler

Register bus channels (and listeners) for system signals.

You can modify what signals your application listens for, and what it does when it receives signals, by modifying :attr:`SignalHandler.handlers`, a dict of {signal name: callback} pairs. The default set is:

   handlers = {'SIGTERM': self.bus.exit,
               'SIGHUP': self.handle_SIGHUP,
               'SIGUSR1': self.bus.graceful,
              }

The :func:`SignalHandler.handle_SIGHUP`` method calls :func:`bus.restart()<cherrypy.process.wspbus.Bus.restart>` if the process is daemonized, but :func:`bus.exit()<cherrypy.process.wspbus.Bus.exit>` if the process is attached to a TTY. This is because Unix window managers tend to send SIGHUP to terminal windows when the user closes them.

Feel free to add signals which are not available on every platform. The :class:`SignalHandler` will ignore errors raised from attempting to register handlers for unknown signals.

Instance Methods [hide private]
 
__init__(self, bus)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_jython_SIGINT_handler(self, signum=None, frame=None) source code
 
subscribe(self)
Subscribe self.handlers to signals.
source code
 
unsubscribe(self)
Unsubscribe self.handlers from signals.
source code
 
set_handler(self, signal, listener=None)
Subscribe a handler for the given signal (number or name).
source code
 
_handle_signal(self, signum=None, frame=None)
Python signal handler (self.set_handler subscribes it for you).
source code
 
handle_SIGHUP(self)
Restart if daemonized, else exit.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  handlers = {}
A map from signal names (e.g.
  signals = {1: 'SIGHUP', 2: 'SIGINT', 3: 'SIGQUIT', 4: 'SIGILL'...
A map from signal numbers to names.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, bus)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

set_handler(self, signal, listener=None)

source code 

Subscribe a handler for the given signal (number or name).

If the optional 'listener' argument is provided, it will be subscribed as a listener for the given signal's channel.

If the given signal name or number is not available on the current platform, ValueError is raised.


Class Variable Details [hide private]

handlers

A map from signal names (e.g. 'SIGTERM') to handlers (e.g. bus.exit).

Value:
{}

signals

A map from signal numbers to names.

Value:
{1: 'SIGHUP',
 2: 'SIGINT',
 3: 'SIGQUIT',
 4: 'SIGILL',
 5: 'SIGTRAP',
 6: 'SIGABRT',
 7: 'SIGBUS',
 8: 'SIGFPE',
...