@@ -0,0 +1,862 @@
+import signal%0Aimport time%0Aimport sys%0A%0Adef run_program():%0A    while True:%0A        time.sleep(1)%0A        print(%22a%22)%0A%0Adef exit_gracefully(signum, frame):%0A    # restore the original signal handler as otherwise evil things will happen%0A    # in raw_input when CTRL+C is pressed, and our signal handler is not re-entrant%0A    signal.signal(signal.SIGINT, original_sigint)%0A    sys.exit(1)%0A    %0A    try:%0A        if raw_input(%22%5CnReally quit? (y/n)%3E %22).lower().startswith('y'):%0A            sys.exit(1)%0A%0A    except KeyboardInterrupt:%0A        print(%22Ok ok, quitting%22)%0A        sys.exit(1)%0A%0A    # restore the exit gracefully handler here%0A    signal.signal(signal.SIGINT, exit_gracefully)%0A%0Aif __name__ == '__main__':%0A    # store the original SIGINT handler%0A    original_sigint = signal.getsignal(signal.SIGINT)%0A    signal.signal(signal.SIGINT, exit_gracefully)%0A    run_program()%0A

add exitBySignal