[apycotlib] also try to get a human-readable description of the signal
authorJulien Cristau <julien.cristau@logilab.fr>
Tue, 17 Dec 2013 11:13:04 +0100
changeset 1474 d7529125ba8a
parent 1473 4a938c54cc70
child 1475 2a7c0ab3f126
[apycotlib] also try to get a human-readable description of the signal Sadly the stdlib doesn't expose strsignal, so hack around it with ctypes.
_apycotlib/__init__.py
--- a/_apycotlib/__init__.py	Fri Oct 18 14:08:10 2013 +0200
+++ b/_apycotlib/__init__.py	Tue Dec 17 11:13:04 2013 +0100
@@ -26,6 +26,7 @@
 from subprocess import STDOUT, Popen
 from tempfile import TemporaryFile
 import signal
+import ctypes
 
 from logilab.common.textutils import splitstrip
 
@@ -39,6 +40,16 @@
 SIGNUM_TO_NAME = dict((getattr(signal, name), name) for name in dir(signal)
                       if name.startswith('SIG') and '_' not in name)
 
+try:
+    strsignal = ctypes.CDLL(None).strsignal
+    strsignal.restype = ctypes.c_char_p
+except AttributeError:
+    pass
+else:
+    for signum in SIGNUM_TO_NAME:
+        SIGNUM_TO_NAME[signum] += ' (%s)' % strsignal(signum)
+
+
 def register(category, klass):
     """register a class"""
     REGISTRY[category][klass.id] = klass