Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rwilcox/149387 to your computer and use it in GitHub Desktop.
Save rwilcox/149387 to your computer and use it in GitHub Desktop.
from __future__ import with_statement
import pdb
import sys
from contextlib import contextmanager
@contextmanager
def local_post_mortem():
"""Use this in a with statement to break into the PDB if the stament throws an exception"""
try:
yield
except:
err, detail, tb = sys.exc_info()
pdb.post_mortem(tb)
# EXAMPLE FOLLOWS:
#=========================================
def main():
with local_post_mortem():
1 + "a"
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment