vim - Nice general way to always invoke python debugger upon exception -


i'd have debugger run post_mortem() time exception encountered, without having modify source i'm working on. see lots of examples involve wrapping code in try/except block, i'd have run, regardless of i'm working on.

i worked on python wrapper script got ugly , pretty unusable.

i use pudb, api-equivalent pdb, pdb-specific answer fine. run code within editor (vim) , have pm come time exception encountered.

it took few months of not doing it, happened stumble upon solution. i'm sure nothing new more experienced.

i have following in environment:

export pythonuserbase=~/.python export pythonpath=$pythonpath:$pythonuserbase 

and have following file:

~/.python/lib/python2.7/site-packages/usercustomize.py 

with following contents:

import traceback import sys  try:     import pudb debugger except importerror:     import pdb debugger  def drop_debugger(type, value, tb):   traceback.print_exception(type, value, tb)   debugger.pm()  sys.excepthook = drop_debugger  __builtins__['debugger'] = debugger __builtins__['st'] = debugger.set_trace 

now, whether interactively or otherwise, debugger jumps in upon exception. might nice smarten some.

it's important make sure have no no-global-site-packages.txt in site-packages. disable usercustomize module default site.py (my virtualenv had no-global-site-packages.txt)

just in case others, left in bit modifying __builtins__. find quite handy able rely on tools being available.

flavor taste.


Comments