Skip to content

pdb: breakpoint() is ignored after quitting a previous session with q #160643

Open

Description

@tonghuaroot

Bug description:

Since gh-138641 (#159918, shipped in 3.15.1 and backported to 3.14), Bdb.set_trace() returns early when self.enterframe is set. Bdb.set_enterframe() clears it after yield without try/finally, so when an exception escapes trace_dispatch(), for example BdbQuit after q in the interactive interpreter, enterframe stays set and every later breakpoint() is ignored.

# printf 'q\nq\nq\n' | python repro.py
import sys, bdb
sys.ps1 = '>>> '   # as in the interactive interpreter
def f(i):
    breakpoint()
    return i
for i in range(3):
    try:
        print('call', i, '->', f(i))
    except bdb.BdbQuit:
        print('BdbQuit caught', i)

On main only the first call stops:

> .../repro.py(5)f()
-> breakpoint()
(Pdb) BdbQuit caught 0
call 1 -> 1
call 2 -> 2

On 3.14.7 the debugger stops on every call. The same happens in a real REPL: call a function that has breakpoint(), type q, call it again, and it no longer stops.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions