I do post mortem debugging a bunch, but I learned something new regarding using python -m pdb and also using pdb.post_mortem() from the except block. For the later I'd usually do a breakpoint() in the except block, but of course that doesn't actually get me where I really want to be, so I end up having to move except blocks up to find a better place to put that, so pdb.post_mortem() sounds great. For the former case where the exception would bubble all the way up, what I've always done is run python -i t.py, then when the exception is raised I'll get dropped into an interactive python console. From there I can do import pdb; pdb.pm(). pdb.pm() is basically like pdb.post_mortem() except instead of debugging the current exception, it debugs the last exception.
@ankushm3t Жыл бұрын
If you use ipython, postmortem debugger can be automatically called on exception using "%pdb" magic.