There are two main ways to do post-mortem debugging in Python with PDB:
- “Caught” exceptions: use a try/catch with
pdb.pm() - “Uncaught” exceptions: register
sys.excepthookand usepdb.post_mortem
Option 1:
try:
1 / 0
except ArithmeticError as exc:
import pdb
pdb.pm()Option 2:
import sys
import pdb
def auto_postmortem(typ, value, tb):
pdb.post_mortem()
sys.excepthook = auto_postmortem
1 / 0See also
If neither of these are enough for you… see Catching all exceptions. Danger ahead.