Skip to content

Instantly share code, notes, and snippets.

@bmiro
Created October 10, 2017 12:55
Show Gist options
  • Save bmiro/adbdedf770d332a7a1cae0933b183488 to your computer and use it in GitHub Desktop.
Save bmiro/adbdedf770d332a7a1cae0933b183488 to your computer and use it in GitHub Desktop.
Python signal example for Ctrl+C
import signal
import sys
from time import sleep
def sig_h(signal, frame):
global n
print("Signal! n: {}".format(n))
signal.signal(signal.SIGINT, sig_h)
n = 0
while True:
print(n)
sleep(1)
n += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment