Skip to content

Commit

Permalink
manager.py: fixed SIGINT handler to work with gevent quirks
Browse files Browse the repository at this point in the history
  • Loading branch information
trey0 committed Nov 25, 2012
1 parent 5b816b6 commit daf1c65
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions geocamPycroraptor2/manager.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ def __init__(self, opts):
self._postQuitHandler = None self._postQuitHandler = None


def _getSignalsToHandle(self): def _getSignalsToHandle(self):
result = [signal.SIGHUP, signal.SIGTERM] return [signal.SIGHUP, signal.SIGINT, signal.SIGTERM]
if self._opts.foreground:
result.append(signal.SIGINT) def _disableGeventDefaultSigintHandler(self):
return result h = gevent.hub.get_hub()
if h.keyboard_interrupt_signal is not None:
h.keyboard_interrupt_signal.cancel()
h.keyboard_interrupt_signal = None


def _start(self): def _start(self):
fmt = log.UtcFormatter('%(asctime)s %(name)s n %(message)s') fmt = log.UtcFormatter('%(asctime)s %(name)s n %(message)s')
Expand Down Expand Up @@ -75,6 +78,7 @@ def _start(self):
self._logger.debug('installing signal handlers') self._logger.debug('installing signal handlers')
for sig in self._getSignalsToHandle(): for sig in self._getSignalsToHandle():
signal.signal(sig, self._handleSignal) signal.signal(sig, self._handleSignal)
gevent.spawn(self._disableGeventDefaultSigintHandler)


# load ports config # load ports config
self._ports = loadConfig(self._config.PORTS) self._ports = loadConfig(self._config.PORTS)
Expand All @@ -96,12 +100,13 @@ def _start(self):
self._jobs = [] self._jobs = []
self._jobs.append(gevent.spawn(self._cleanupChildren)) self._jobs.append(gevent.spawn(self._cleanupChildren))


def _handleSignal(self, sigNum, frame):
def _handleSignal(self, sigNum='unknown', frame=None):
if sigNum in SIG_VERBOSE: if sigNum in SIG_VERBOSE:
desc = SIG_VERBOSE[sigNum]['sigName'] desc = SIG_VERBOSE[sigNum]['sigName']
else: else:
desc = 'unknown' desc = 'unknown'
self._logger.info('caught signal %d (%s), shutting down', self._logger.info('caught signal %s (%s), shutting down',
sigNum, desc) sigNum, desc)
try: try:
self.quit() self.quit()
Expand Down

0 comments on commit daf1c65

Please sign in to comment.