import signal import time def handler(a, b): print("Handler") time.sleep(1) signal.signal(signal.SIGINT, handler)