#!/usr/bin/python3.6 """https://bugs.python.org/issue1054041 playground.""" import os import signal import sys import time if __name__ == '__main__': try: print('pid', os.getpid(), 'sleeping...') time.sleep(1000000) except KeyboardInterrupt: print('KeyboardInterrupt caught') if len(sys.argv) > 1: n = signal.SIGINT + 128 print('exiting', n) sys.exit(n) else: print('triggering the SIGINT SIG_DFL handler.') signal.signal(signal.SIGINT, signal.SIG_DFL) os.kill(os.getpid(), signal.SIGINT)