Skip to content

Instantly share code, notes, and snippets.

@jlfwong
Created May 7, 2012 18:00
Show Gist options
  • Save jlfwong/2629337 to your computer and use it in GitHub Desktop.
Save jlfwong/2629337 to your computer and use it in GitHub Desktop.
pdb debug decorator
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