Skip to content

Instantly share code, notes, and snippets.

@cameron
Created December 4, 2013 10:05
Show Gist options
  • Save cameron/7785159 to your computer and use it in GitHub Desktop.
Save cameron/7785159 to your computer and use it in GitHub Desktop.
Launch pdb on runtime exceptions -- put this in site-packages/sitecustomize.py or somesuch.
# auto stop in pdb on noneexceptions
def info(exc_type, value, tb):
# dont do anything for keyboard interrupts or exit signals
if exc_type in (KeyboardInterrupt, SystemExit):
return
if hasattr(sys, 'ps1') or not sys.stderr.isatty():
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(exc_type, value, tb)
else:
import traceback, pdb
# we are NOT in interactive mode, print the exception...
traceback.print_exception(exc_type, value, tb)
print
# ...then start the debugger in post-mortem mode.
pdb.pm()
sys.excepthook = info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment