Created
September 20, 2022 08:10
-
-
Save coseos/875682dd492e92d99ac50b3720a447da to your computer and use it in GitHub Desktop.
This file contains 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/python | |
# This is a template on how to add a CTRL-C handler in your Python script | |
# | |
# With this handler, you can include a proper cleanup before the script is terminated. | |
# | |
from signal import signal, SIGINT | |
from sys import exit | |
def handler(signal_received, frame): | |
# Handle any cleanup here | |
print('SIGINT or CTRL-C detected. Exiting gracefully') | |
exit(0) | |
if __name__ == '__main__': | |
# Tell Python to run the handler() function when SIGINT is recieved | |
signal(SIGINT, handler) | |
print('Running. Press CTRL-C to exit.') | |
while True: | |
# Do nothing and hog CPU forever until SIGINT received. | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment