Permalink
Browse files

manager.py: fixed SIGINT handler to work with gevent quirks

  • Loading branch information...
1 parent 5b816b6 commit daf1c650ef1f3232108f337b9376ed32269cc1ba @trey0 trey0 committed Nov 25, 2012
Showing with 11 additions and 6 deletions.
  1. +11 −6 geocamPycroraptor2/manager.py
@@ -41,10 +41,13 @@ def __init__(self, opts):
self._postQuitHandler = None
def _getSignalsToHandle(self):
- result = [signal.SIGHUP, signal.SIGTERM]
- if self._opts.foreground:
- result.append(signal.SIGINT)
- return result
+ return [signal.SIGHUP, signal.SIGINT, signal.SIGTERM]
+
+ def _disableGeventDefaultSigintHandler(self):
+ 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):
fmt = log.UtcFormatter('%(asctime)s %(name)s n %(message)s')
@@ -75,6 +78,7 @@ def _start(self):
self._logger.debug('installing signal handlers')
for sig in self._getSignalsToHandle():
signal.signal(sig, self._handleSignal)
+ gevent.spawn(self._disableGeventDefaultSigintHandler)
# load ports config
self._ports = loadConfig(self._config.PORTS)
@@ -96,12 +100,13 @@ def _start(self):
self._jobs = []
self._jobs.append(gevent.spawn(self._cleanupChildren))
- def _handleSignal(self, sigNum, frame):
+
+ def _handleSignal(self, sigNum='unknown', frame=None):
if sigNum in SIG_VERBOSE:
desc = SIG_VERBOSE[sigNum]['sigName']
else:
desc = 'unknown'
- self._logger.info('caught signal %d (%s), shutting down',
+ self._logger.info('caught signal %s (%s), shutting down',
sigNum, desc)
try:
self.quit()

0 comments on commit daf1c65

Please sign in to comment.