Created
March 19, 2016 11:28
-
-
Save rtfpessoa/e3b1fe0bbfcd8ac853bf to your computer and use it in GitHub Desktop.
Handle CTRL+C in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import signal | |
import sys | |
def signal_handler(signal, frame): | |
sys.exit(0) | |
signal.signal(signal.SIGINT, signal_handler) |
Yes. I got your points. Thank you so much for this solution.
Perfect solution, still working with python 3.8, thanks.
Can confirm, still works.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
signal_handler
is just the fuction you are passing tosignal.signal(..)
in line 9.This was done a long time ago, but those are just the parameters that the runtime give you so you can have more context about the signal.