Created
December 30, 2011 08:14
-
-
Save atdt/1538643 to your computer and use it in GitHub Desktop.
DaemonContext (for python-daemon) that handles SIGHUPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import daemon | |
| import signal | |
| class SighupDaemon(daemon.DaemonContext): | |
| """ A DaemonContext that catches SIGHUPs """ | |
| # get default signal handler map for this system | |
| defaults = daemon.daemon.make_default_signal_map() | |
| def __init__(self, *args, **kwargs): | |
| signal_map = kwargs.setdefault('signal_map', {}) | |
| signal_map.update(self.defaults) | |
| signal_map.setdefault(signal.SIGHUP, 'sighup_handler') | |
| super(SighupDaemon, self).__init__(*args, **kwargs) | |
| def sighup_handler(self, signum, frame): | |
| # handler code goes here | |
| print "Caught SIGHUP!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment