Get signal names from numbers in Python
There is none, but if you don't mind a little hack, you can generate it like this:
import signal
dict((k, v) for v, k in reversed(sorted(signal.__dict__.items()))
if v.startswith('SIG') and not v.startswith('SIG_'))
With the addition of the signal.Signals
enum
in Python 3.5 this is now as easy as:
>>> import signal
>>> signal.SIGINT.name
'SIGINT'
>>> signal.SIGINT.value
2
>>> signal.Signals(2).name
'SIGINT'
>>> signal.Signals['SIGINT'].value
2