that's probably not the way to do to it.
you should modify/extend the existing pdb.py. the code looks like this:
while True:
try:
pdb._runscript(mainpyfile)
if pdb._user_requested_quit:
break
print "The program finished and will be restarted"
except:
traceback.print_exc()
print "Uncaught exception. Entering post mortem debugging"
print "Running 'cont' or 'step' will restart the program"
t = sys.exc_info()[2]
pdb.interaction(None, t)
print "Post mortem debugger finished. The "+mainpyfile+" will be restarted"
it looks like you could replace `pdb._runscript(mainpyfile)' with something like
runpy.run_module(sys.argv[0], run_name="__main__", alter_sys=True)
(from PEP 338).
not a complete solution, and i haven't tested it, but maybe it helps.
edit: but for a simpler solution, for a single script, your script probably ends with something like:
if __name__ == '__main__':
call_main_function()
you just replace it it
if __name__ == '__main__':
try:
call_main_function()
except:
import pdb
t = sys.exc_info()[2]
pdb.interaction(None, t)
(last code stolen from pdb.py, that's exactly what it does when it gets an unhandled exception).