[apycotlib] when a child dies from a signal, look up the signal name
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 18 Oct 2013 14:08:10 +0200
changeset 1473 4a938c54cc70
parent 1472 bc28ed883351
child 1474 d7529125ba8a
[apycotlib] when a child dies from a signal, look up the signal name Should make for more readable logging.
_apycotlib/__init__.py
--- a/_apycotlib/__init__.py	Thu Jun 20 10:46:42 2013 +0200
+++ b/_apycotlib/__init__.py	Fri Oct 18 14:08:10 2013 +0200
@@ -25,6 +25,7 @@
 from os.path import exists, join, dirname
 from subprocess import STDOUT, Popen
 from tempfile import TemporaryFile
+import signal
 
 from logilab.common.textutils import splitstrip
 
@@ -34,6 +35,10 @@
             'preprocessor': {},
             'checker': {}}
 
+# get all signal names, ignore SIG_IGN/SIG_DFL
+SIGNUM_TO_NAME = dict((getattr(signal, name), name) for name in dir(signal)
+                      if name.startswith('SIG') and '_' not in name)
+
 def register(category, klass):
     """register a class"""
     REGISTRY[category][klass.id] = klass
@@ -281,9 +286,9 @@
                 cmd_status = self.non_zero_status_code
             else:
                 # negative status mean the process have been killed by a signal
-                short_msg = u'`%s` killed by signal %s' % (cmd, status)
+                status *= -1
+                short_msg = u'`%s` killed by signal %s' % (cmd, SIGNUM_TO_NAME.get(status, status))
                 # Get the signal number
-                status *= -1
                 cmd_status = KILLED
                 # XXX we need detection of common limit here
             msg = self.append_output_messages(short_msg, stdout, stderr, unparsed)