Created
March 8, 2018 19:07
-
-
Save jorandradefig/a39196e7d65d360f9942ce1e7071927e to your computer and use it in GitHub Desktop.
Ctrl-C Signal Handler
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
| import signal | |
| import sys | |
| from time import sleep | |
| SIGINT = False | |
| def signal_handler(signal, frame): | |
| print('Ctrl + C received...') | |
| global SIGINT | |
| SIGINT = True | |
| # Set up the signal handler | |
| signal.signal(signal.SIGINT, signal_handler) | |
| while True: | |
| # If Ctrl + C was pressed | |
| if SIGINT: | |
| print("Stopping loop since beginning...") | |
| break | |
| # While Ctrl + C hasn't been pressed | |
| print("Processing PDF...") | |
| sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment