summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rivera <rivera@joel.mx>2016-03-10 00:29:45 -0600
committerJoel Rivera <rivera@joel.mx>2016-03-10 00:29:45 -0600
commit12bdd60a936815333c32bc19f9c40930de1ea14f (patch)
treefd90b9e178a92da3c324c9ad472feb31fc23672b
parentda1046c39ca7bb7c71c5f5d79f76f1cd9709f25c (diff)
downloadcherrypy-12bdd60a936815333c32bc19f9c40930de1ea14f.tar.gz
Add additional validation to determine if the process is running as a daemon on the SignalHandler Plugin,
the modification allow us to run the testsuite inside CI tools without leaving hanging the whole testsuite.
-rw-r--r--cherrypy/process/plugins.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/cherrypy/process/plugins.py b/cherrypy/process/plugins.py
index 2bf07776..0ec585c0 100644
--- a/cherrypy/process/plugins.py
+++ b/cherrypy/process/plugins.py
@@ -109,12 +109,35 @@ class SignalHandler(object):
self.handlers['SIGINT'] = self._jython_SIGINT_handler
self._previous_handlers = {}
+ # used to determine is the process is a daemon in `self._is_daemonized`
+ self._original_pid = os.getpid()
+
def _jython_SIGINT_handler(self, signum=None, frame=None):
# See http://bugs.jython.org/issue1313
self.bus.log('Keyboard Interrupt: shutting down bus')
self.bus.exit()
+ def _is_daemonized(self):
+ """Return boolean indicating if the current process is
+ running as a daemon.
+
+ The criteria to determine the `daemon` condition is to verify
+ if the current pid is not the same as the one that got used on
+ the initial construction of the plugin *and* the stdin is not
+ connected to a terminal.
+
+ The sole validation of the tty is not enough when the plugin
+ is executing inside other process like in a CI tool
+ (Buildbot, Jenkins).
+ """
+ if (self._original_pid != os.getpid() and
+ not os.isatty(sys.stdin.fileno())):
+ return True
+ else:
+ return False
+
+
def subscribe(self):
"""Subscribe self.handlers to signals."""
for sig, func in self.handlers.items():
@@ -180,13 +203,13 @@ class SignalHandler(object):
def handle_SIGHUP(self):
"""Restart if daemonized, else exit."""
- if os.isatty(sys.stdin.fileno()):
+ if self._is_daemonized():
+ self.bus.log("SIGHUP caught while daemonized. Restarting.")
+ self.bus.restart()
+ else:
# not daemonized (may be foreground or background)
self.bus.log("SIGHUP caught but not daemonized. Exiting.")
self.bus.exit()
- else:
- self.bus.log("SIGHUP caught while daemonized. Restarting.")
- self.bus.restart()
try: