Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jorandradefig/a39196e7d65d360f9942ce1e7071927e to your computer and use it in GitHub Desktop.

Select an option

Save jorandradefig/a39196e7d65d360f9942ce1e7071927e to your computer and use it in GitHub Desktop.
Ctrl-C Signal Handler
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