Skip to content

Instantly share code, notes, and snippets.

@takluyver
Created May 13, 2016 19:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save takluyver/8c25dcf1f175159b0c741207a6dda94a to your computer and use it in GitHub Desktop.
Save takluyver/8c25dcf1f175159b0c741207a6dda94a to your computer and use it in GitHub Desktop.
Debug on interrupt
$ python3 interrupt-debug.py
0
1
2
3
^C--Return--
> /home/takluyver/scratch/interrupt-debug.py(6)handle_sigint()->None
-> pdb.set_trace()
(Pdb) p a
4
(Pdb)
import signal
import time
import pdb
def handle_sigint(signo, frame):
pdb.set_trace()
signal.signal(signal.SIGINT, handle_sigint)
for a in range(10000):
time.sleep(0.5)
print(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment