Created
July 18, 2009 03:14
-
-
Save rwilcox/149387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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