Get signal names from numbers in Python
        Posted  
        
            by Brian M. Hunt
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Brian M. Hunt
        
        
        
        Published on 2010-03-31T01:51:47Z
        Indexed on 
            2010/03/31
            2:03 UTC
        
        
        Read the original article
        Hit count: 636
        
Is there a way to map a signal number (e.g. signal.SIGINT) to its respective name (i.e. "SIGINT")?
I'd like to be able to print the name of a signal in the log when I receive it, however I cannot find a map from signal numbers to names in Python, i.e.
import signal
def signal_handler(signum, frame):
    logging.debug("Received signal (%s)" % sig_names[signum])
signal.signal(signal.SIGINT, signal_handler)
For some dictionary sig_names, so when the process receives SIGINT it prints:
Received signal (SIGINT)
Thank you.
© Stack Overflow or respective owner