Python Glossary Русский

all Python 3pdbfunction

pdb.set_trace()

breakpoints

Stops the program in the debugger where it is called. Since Python 3.7 people usually write breakpoint() instead.

Syntax

pdb.set_trace(*, header=None)

Since 3.13 it stops on the set_trace() line itself; earlier it stopped on the next line. A forgotten call in a solution is dangerous: under an autograder the debugger starts reading commands from stdin and eats the test's input. breakpoint() is better because PYTHONBREAKPOINT=0 disables it without editing code, though running with -E or -I ignores that variable.

Examples

import io, sys, pdb
def f(x):
    pdb.set_trace()
    y = x * 2
    return y
sys.stdin = io.StringIO('p x\nc\n')
sys.stdout = log = io.StringIO()
r = f(21)
sys.stdout = sys.__stdout__
print(r, log.getvalue().split('(Pdb) ')[1].strip())  # → 42 21
import sys
sys.breakpointhook = lambda *a, **k: print('точка останова пропущена')
breakpoint()  # → точка останова пропущена — так breakpoint() можно перенаправить

See also

Open in the full glossarydocs.python.orgReport an inaccuracy