def run_with_pdb(cmd, *args, **kwargs):
# Stolen from pdb.main
pdb_context = pdb.Pdb()
try:
ret = pdb_context.runcall(cmd, **kwargs)
print("The program finished")
return ret
except pdb.Restart:
print("Restarting %s with arguments: %s, %s" % (cmd.__name__, args, kwargs))
# Yes, that's a hack
return run_with_pdb(cmd, *args, **kwargs)
except SystemExit:
# In most cases SystemExit does not warrant a post-mortem session.
print("The program exited via sys.exit(). Exit status:", end=' ')
print(sys.exc_info()[1])
except SyntaxError:
traceback.print_exc()
sys.exit(1)
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_context.interaction(None, t)
print("Post mortem debugger finished.")
评论列表
文章目录