Skip to content

Instantly share code, notes, and snippets.



Forked from notsobad/
Last active Jun 25, 2018
What would you like to do?
Put this in python module dir, on mac: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
or /usr/local/lib/python3.*/site-packages
Run your script this way:
>> python -m autopdb /path/
import bdb
import sys
def info(type, value, tb):
if hasattr(sys, 'ps1') \
or not sys.stdin.isatty() \
or not sys.stdout.isatty() \
or not sys.stderr.isatty() \
or issubclass(type, bdb.BdbQuit) \
or issubclass(type, SyntaxError):
# we are in interactive mode or we don't have a tty-like
# device, so we call the default hook
sys.__excepthook__(type, value, tb)
import traceback, pdb
# we are NOT in interactive mode, print the exception...
traceback.print_exception(type, value, tb)
# ...then start the debugger in post-mortem mode.
sys.excepthook = info
# execfile(sys.argv[1]) # py2
exec(open(sys.argv[1], 'rb').read()) # py3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment