import signal
import sys
import time
def sigint_handler(signal, frame):
print "signal"
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
while 1:
try:
print "text"
time.sleep(2)
except KeyboardInterrupt:
print "keybi"
exit(0)
except:
print "except"
continue
When I press Ctrl-C I see "signal" and "except" and the program doesn't exit.
Why doesn't the program exit, while it apparently reaches
sys.exit(0)
?Why doesn't the program flow reach the
KeyboardInterrupt
section?What is the concise way to make Ctrl-C work and handle each
except:
case separately in different places without exiting?