1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| import signal from sys import exit
def handler(signal_received, frame): print('SIGINT or CTRL-C detected. Exiting gracefully') exit(0)
if __name__ == '__main__': signal.signal(signal.SIGINT, self.ctrl_exit_handler) signal.signal(signal.SIGTSTP, self.ctrl_exit_handler)
print('Running. Press CTRL-C to exit.') while True: pass
|