Skip to content

Instantly share code, notes, and snippets.

@jterrace
Created July 19, 2012 16:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jterrace/3145174 to your computer and use it in GitHub Desktop.
Drops python to a debugger on unhandled exceptions
"""Import this module to make python drop to the debugger
when an undhandled exception is raised.
Original script from:
http://code.activestate.com/recipes/65287/
"""
import sys
__old_excepthook__ = sys.excepthook
def info(type, value, tb):
if hasattr(sys, 'ps1') or \
not sys.stderr.isatty() or \
not sys.stdin.isatty() or \
not sys.stdout.isatty() or \
type == SyntaxError:
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
__old_excepthook__(type, value, tb)
else:
# dump the exception and then start the debugger in
# post-mortem mode.
import traceback, pdb
traceback.print_exception(type, value, tb)
print
pdb.pm()
sys.excepthook = info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment