And so I did. I can't work out if this is too trivial to upload to the cheese shop, but if you create a file called "signal_handler.py", and import it from anywhere in your code, you will magically link up the SIGINT (what gets sent by control-C) to the Python debugger. For extra win, it will try to initiate "ipdb" if you have it. I haven't actually tested it on pdb, but it's hard to see how it could fail to work. Besides, you should be using ipdb (pip install ipdb).
import signal try: import ipdb as pdb except: import pdb def handle_signal(signal_number, frame_stack): pdb.set_trace() signal.signal(signal.SIGINT, handle_signal)
Voila! Now, next time you are watching your app run and you need to start the debugger when you least expected it, you can just do it!