Python 3 reference · Built-in Functions

Python breakpoint() Function

Pause the program and open the debugger at this line. It calls sys.breakpointhook(), which starts pdb by default.

Python 3 Since 3.7

Syntax

breakpoint(*args, **kws)

Parameters

ParameterDescription
*args, **kws optional Passed on to sys.breakpointhook().

Return value

Whatever the hook returns (usually None).

Examples

What happens when breakpoint() runsTry it yourself
import sys

# Replace the hook so this example doesn't wait for debugger input
sys.breakpointhook = lambda *args, **kws: print("debugger would open here")

total = 0
for n in [3, 5]:
    total += n
    breakpoint()
print("total:", total)

sys.breakpointhook = sys.__breakpointhook__  # restore the default

Output

debugger would open here
debugger would open here
total: 8
Configure or disable itTry it yourself
import os, sys

# The PYTHONBREAKPOINT environment variable controls the hook:
#   PYTHONBREAKPOINT=0                 -> breakpoint() does nothing
#   PYTHONBREAKPOINT=module.function   -> call that function instead of pdb
print(sys.__breakpointhook__.__name__)  # the default hook
print(os.environ.get("PYTHONBREAKPOINT", "not set"))

Output

breakpointhook
not set

Good to know

  • In a terminal, breakpoint() drops you into pdb: type n (next line), s (step into), c (continue), p name (print a value) and q (quit).
  • Set PYTHONBREAKPOINT=0 to make every breakpoint() call do nothing, so a forgotten one can't hang production.
  • Remove breakpoints before committing; linters can flag them.

Version history

VersionChange
Python 3.7Added