bronx.system.interrupt

This module handles advanced signal catching.

Classes

class bronx.system.interrupt.SignalInterruptHandler(signals=(<Signals.SIGHUP: 1>, <Signals.SIGINT: 2>, <Signals.SIGQUIT: 3>, <Signals.SIGTRAP: 5>, <Signals.SIGABRT: 6>, <Signals.SIGFPE: 8>, <Signals.SIGUSR1: 10>, <Signals.SIGUSR2: 12>, <Signals.SIGTERM: 15>), emitlogs=True)[source]

Bases: object

Handler class to deal with system signals.

Parameters:
  • signals – list/tuple of signals that will be caught

  • emitlogs – emit log messages

For each of the signals specified to the class constructor, this signal handler is able to switch on and off a customised signal handler that will raise a SignalInterruptError exception when the signal is received by the python shell.

An exception is made with SIGINT that will trigger the usual Python’s KeyboardInterrupt exception.

Example:

a simple way of activating/deactivating the signal handlers:

shandler = SignalInterruptHandler()
shandler.activate()

# In this portion of the script an exception is raised when a signal is
# sent to the python shell

print 'Is the signal handler active?', shandler.active

shandler.deactivate()

# In this portion of the script the python shell will abruptly stop if
# a signal is received
Example:

the same thing but using a context:

with SignalInterruptHandler() as shandler:

    # In this portion of the script an exception is raised when a signal is
    # sent to the python shell

    print 'Is the signal handler active?', shandler.active

# In this portion of the script the python shell will abruptly stop if
# a signal is received
activate()[source]

Activate the signal handlers.

property active

Are the singal handlers active ?

deactivate()[source]

Deactivate the signal handlers and restore the previous ones.

property signals

List of the signals catched by the signal handlers.

Exceptions

exception bronx.system.interrupt.SignalInterruptError[source]

Bases: BaseException

Exception raised when a system signal is caught.