python-remote-pdb
python-remote-pdb copied to clipboard
Add `post_mortem()`
It would be useful to have a post_mortem
function like pdb
has. This would allow calling remote_pdb
right after an exception is raise (if it's raised). Like this:
try:
code_which_can_fail()
except:
extype, value, tb = sys.exc_info()
traceback.print_exc()
remote_pdb.post_mortem(tb)
This is useful in environments where remote_pdb
can't be called directly
Something like this would work:
def post_mortem(t=None):
# handling the default
if t is None:
# sys.exc_info() returns (type, value, traceback) if an exception is
# being handled, otherwise it returns None
t = sys.exc_info()[2]
if t is None:
raise ValueError("A valid traceback must be passed if no " "exception is being handled")
p = remote_pdb.RemotePdb(
host=os.environ.get("REMOTE_PDB_HOST", "127.0.0.1"), port=int(os.environ.get("REMOTE_PDB_PORT", "0")),
# other args
)
p.reset()
p.interaction(None, t)
I can make a PR if this feature is welcome
Found a similar issue at #12, the implementation above is a working post_mortem