all Python 3pdbfunction
pdb.pm()
post-mortem debugging
Post-mortem debugging of the last uncaught exception in an interactive session: python -i script.py, then pdb.pm().
Syntax
pdb.pm()
pm() reads sys.last_exc (sys.last_traceback before 3.12), and only the interactive interpreter sets them after an unhandled exception. A normal script has no such attributes and pm() fails with AttributeError; use post_mortem() inside except there. `python -m pdb script.py` enters post-mortem mode by itself.
Examples
import pdb
try:
pdb.pm()
except AttributeError as e:
print(type(e).__name__) # → AttributeError — в скрипте нет sys.last_exc
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy