This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author blueyed
Recipients blueyed
Date 2019-03-21.08:28:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1553156880.66.0.415237926561.issue36388@roundup.psfhosted.org>
In-reply-to
Content
It seems like the "debug" command is not properly handled with "post_mortem()".

It appears due to using `sys.settrace(self.trace_dispatch)` in the end of `do_debug`, although no tracing is installed with post_mortem in the first place.


More info:

Given the following test script:

```
def exc():
    raise Exception()


try:
    exc()
except Exception:
    import pdb
    pdb.post_mortem()
```

The behavior with just "quit" is fine:

```
% python3.8 t_pdb.py
> …/project/t_pdb.py(2)exc()
-> raise Exception()
(Pdb) q
```

But when using `debug` inside of it, it will stop at `cmd.postcmd`, and you have to use "continue" twice:

```
% python3.8 t_pdb.py
> …/project/t_pdb.py(2)exc()
-> raise Exception()
(Pdb) debug print(1)
ENTERING RECURSIVE DEBUGGER
> <string>(1)<module>()
((Pdb)) c
1
LEAVING RECURSIVE DEBUGGER
> …/pyenv/3.8-dev/lib/python3.8/cmd.py(159)postcmd()
-> return stop
(Pdb) c
(Pdb) c
```

Also when using `quit` inside of the `debug`:

```
% python3.8 t_pdb.py
> …/project/t_pdb.py(2)exc()
-> raise Exception()
(Pdb) debug print(1)
ENTERING RECURSIVE DEBUGGER
> <string>(1)<module>()
((Pdb)) q
LEAVING RECURSIVE DEBUGGER
> …/pyenv/3.8-dev/lib/python3.8/cmd.py(159)postcmd()
-> return stop
(Pdb) c
(Pdb) c
```

When using `quit` when at `postcmd()` it will even raise `BdbQuit`:

```
% python3.8 t_pdb.py
> …/project/t_pdb.py(2)exc()
-> raise Exception()
(Pdb) debug print(1)
ENTERING RECURSIVE DEBUGGER
> <string>(1)<module>()
((Pdb)) q
LEAVING RECURSIVE DEBUGGER
> …/pyenv/3.8-dev/lib/python3.8/cmd.py(159)postcmd()
-> return stop
(Pdb) q
Traceback (most recent call last):
  File "t_pdb.py", line 6, in <module>
    exc()
  File "t_pdb.py", line 2, in exc
    raise Exception()
Exception

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "t_pdb.py", line 9, in <module>
    pdb.post_mortem()
  File "…/pyenv/3.8-dev/lib/python3.8/pdb.py", line 1626, in post_mortem
    p.interaction(None, t)
  File "…/pyenv/3.8-dev/lib/python3.8/pdb.py", line 352, in interaction
    self._cmdloop()
  File "…/pyenv/3.8-dev/lib/python3.8/pdb.py", line 321, in _cmdloop
    self.cmdloop()
  File "…/pyenv/3.8-dev/lib/python3.8/cmd.py", line 139, in cmdloop
    stop = self.postcmd(stop, line)
  File "…/pyenv/3.8-dev/lib/python3.8/cmd.py", line 159, in postcmd
    return stop
  File "…/pyenv/3.8-dev/lib/python3.8/cmd.py", line 159, in postcmd
    return stop
  File "…/pyenv/3.8-dev/lib/python3.8/bdb.py", line 88, in trace_dispatch
    return self.dispatch_line(frame)
  File "…/pyenv/3.8-dev/lib/python3.8/bdb.py", line 113, in dispatch_line
    if self.quitting: raise BdbQuit
bdb.BdbQuit
```
History
Date User Action Args
2019-03-21 08:28:00blueyedsetrecipients: + blueyed
2019-03-21 08:28:00blueyedsetmessageid: <1553156880.66.0.415237926561.issue36388@roundup.psfhosted.org>
2019-03-21 08:28:00blueyedlinkissue36388 messages
2019-03-21 08:28:00blueyedcreate