Skip to content Skip to sidebar Skip to footer

How To Handle Os Signal In A Python Program?

I am writing a python program which reads from a queue through a infinite while loop. How can I handle signal sent by OS / Keyboard interrupt(CTRL+C) to break from the while loop a

Solution 1:

I think signal module is what you are looking for,

def handler(signum, frame):
    print 'Signal handler called with signal', signum

signal.signal(signal.SIGABRT, handler)

Post a Comment for "How To Handle Os Signal In A Python Program?"