Skip to content

Commit f37daac

Browse files
committed
Let's make post_mortem support passing an exception alone, like pdb.post_mortem does. Also, add an explanation in the README.md
1 parent 15dd1d6 commit f37daac

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ while True:
100100
...
101101
```
102102

103+
### `post_mortem()` function
104+
Debugpy supports a `post_mortem()` function similar to `pdb.post_mortem()`. Call `debugpy.post_mortem(e)` with an exception or `(type(e),e,e.__traceback__)` tuple; or with no arguments in an except block. If the debugger is attached, it will pause execution and start post-mortem debugging of the exception stack as-if an uncaught exception. This respects breakpoint filters set by the debugger by default. When resuming afterward, the program will continue executing as normal (including unwinding the stack further if post_mortem() was invoked in a context manager's `__exit__` for example, or the exception is re-raised). If there's no client attached, this function does nothing, as breakpoint().
105+
103106
## Debugger logging
104107

105108
To enable debugger internal logging via CLI, the `--log-to` switch can be used:

src/debugpy/public_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def trace_this_thread(__should_trace: bool):
214214

215215
@_api()
216216
def post_mortem(
217-
__excinfo: typing.Tuple[type, BaseException, typing.Any] | None = None,
217+
__excinfo: typing.Tuple[type, BaseException, typing.Any] | BaseException | None = None,
218218
as_uncaught: bool = True,
219219
) -> None:
220220
"""Stops the debugger on an unhandled exception.

src/debugpy/server/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ def post_mortem(excinfo=None, as_uncaught=True):
372372
if excinfo is None:
373373
excinfo = sys.exc_info()
374374

375+
if isinstance(excinfo, BaseException):
376+
excinfo = (type(excinfo), excinfo, excinfo.__traceback__)
377+
375378
exctype, value, tb = excinfo
376379
if exctype is None or value is None or tb is None:
377380
log.debug("postmortem() ignored - no exception info")

0 commit comments

Comments
 (0)