I'd like to have my debugger run post_mortem()
any time an exception is encountered, without having to modify the source that I'm working on. I see lots of examples that involve wrapping code in a try/except block, but I'd like to have it always run, regardless of what I'm working on.
I worked on a python wrapper script but that got to be ugly and pretty much unusable.
I use pudb, which is API-equivalent to pdb, so a pdb-specific answer is fine. I run code from within my editor (vim) and would like to have the pm come up any time an exception is encountered.
It took a few months of not doing anything about it, but I happened to stumble upon a solution. I'm sure this is nothing new for the more experienced.
I have the following in my environment:
And I have the following file:
With the following contents:
Now, whether interactively or otherwise, the debugger always jumps in upon an exception. It might be nice to smarten this up some.
It's important to make sure that you have no
no-global-site-packages.txt
in yoursite-packages
. This will disable theusercustomize
module with the defaultsite.py
(my virtualenv had ano-global-site-packages.txt
)Just in case it would help others, I left in the bit about modifying
__builtins__
. I find it quite handy to always be able to rely on some certain tools being available.Flavor to taste.