My application has debug = True
configuration option which turns on many facilities useful for debugging. I figured that it would be a nice idea to enable the debugger when debug mode is turned on, but not the way python -m pdb someapp
works. Instead, I'd like it to behave as if the user entered "cont" right at the startup, so that the debugger appears only when an exception was caught. How do I do that on the source code level?
Asked
Active
Viewed 72 times
2

d33tah
- 10,999
- 13
- 68
- 158
-
[Python debugging tips](http://stackoverflow.com/questions/1623039/python-debugging-tips) SO question could be useful – alex vasi Dec 06 '13 at 17:12
1 Answers
4
import sys
def run_pdb_hook(*args, **kwargs):
import pdb, traceback
traceback.print_exception(*args, **kwargs)
pdb.pm()
if debug:
sys.excepthook = run_pdb_hook

alex vasi
- 5,304
- 28
- 31