Created
May 7, 2012 18:00
-
-
Save jlfwong/2629337 to your computer and use it in GitHub Desktop.
pdb debug decorator
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 functools import wraps | |
import sys | |
import pdb | |
import traceback | |
def pdb_on_error(func): | |
@wraps(func) | |
def pdbd(*args, **kwargs): | |
try: | |
func(*args, **kwargs) | |
except Exception, e: | |
print '\n' + '=' * 30 + ' pdb_on_error ' + '=' * 30 | |
traceback.print_exc(file=sys.stdout) | |
pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__).set_trace() | |
return pdbd | |
# Example usage: | |
@pdb_on_error | |
def method_that_throws(): | |
x = {} | |
x['foo'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment