autotest: don't attempt to install sigalrm handler in mod_wsgi processes

Installing custom signal handlers inside a mod_wsgi process is never
expected to work, as mod_wsgi relies on these signals for its own
purposes, and will intercept attempts to modify them (and emit spam to
the apache error log).

We can detect when running inside a mod_wsgi process, and not even
bother trying to install sigalrm handler in such a case.


Change-Id: I1d012c76068e1fa828f12e75c53b55b9be290b76
Tested-by: Aviv Keshet <>
Reviewed-by: Richard Barnette <>
Commit-Queue: Aviv Keshet <>
diff --git a/client/common_lib/cros/ b/client/common_lib/cros/
index 0c8dffb..1b268e8 100644
--- a/client/common_lib/cros/
+++ b/client/common_lib/cros/
@@ -11,6 +11,16 @@
 from autotest_lib.client.common_lib import error
+_in_mod_wsgi = False
+    # Per mod_wsgi documentation, this import will only suceed if we are running
+    # inside a mod_wsgi process.
+    # pylint: disable=unused-import
+    from mod_wsgi import version
+    _in_mod_wsgi = True
+    pass
 def install_sigalarm_handler(new_handler):
@@ -26,6 +36,12 @@
                         the numbers 1,0 respectively.
     @return: True if the installation of new_handler succeeded, False otherwise.
+    # Installing signal handlers does not and is never expected to work if we're
+    # running in a mod_wsgi process.
+    if _in_mod_wsgi:
+        logging.warning('Cannot install sigalarm handler in mod_wsgi process.')
+        return False
     if (new_handler is None or
         (not callable(new_handler) and
          new_handler != signal.SIG_IGN and