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
| Parameter | Description |
|---|---|
*args, **kws optional |
Passed on to sys.breakpointhook(). |
Return value
Whatever the hook returns (usually None).
Examples
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
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: typen(next line),s(step into),c(continue),p name(print a value) andq(quit). - Set
PYTHONBREAKPOINT=0to make everybreakpoint()call do nothing, so a forgotten one can't hang production. - Remove breakpoints before committing; linters can flag them.
Version history
| Version | Change |
|---|---|
| Python 3.7 | Added |
Related
print()· Write values to standard output (or a file), separated by spaces and followed by a newline. Both are configurable.help()· Show the built-in help for a function, class, module or keyword: its signature and documentation. Mostly used in the REPL.- Python Try...Except · tutorial