#!/usr/bin/python3.6 import os import sys import time import signal import threading import _thread STATUS_CONTROL_C_EXIT = 0xC000013A - 2**32 if __name__ == '__main__': print('pid', os.getpid(), 'sleeping...') try: threading.Timer(1, _thread.interrupt_main).start() time.sleep(5) except KeyboardInterrupt: print('KeyboardInterrupt caught') n = STATUS_CONTROL_C_EXIT if len(sys.argv) > 1 else 1 print('exiting', n) sys.exit(n)