Python 3.7+sysfunction
sys.breakpointhook()
debugging and tracing
The function called by the built-in breakpoint(). By default it opens pdb; replace it to choose another debugger or to disable the stops.
Syntax
sys.breakpointhook = hook
A forgotten breakpoint() in code run by an autograder waits for input and hangs the run — the environment variable PYTHONBREAKPOINT=0 turns every such call into a no-op. But once the program assigns sys.breakpointhook itself, the variable is no longer consulted. breakpoint(*args, **kw) passes its arguments to the hook unchanged and returns its result. The original is sys.__breakpointhook__.
Examples
import sys
def stop(*args, **kw):
print('стоп', args, kw)
sys.breakpointhook = stop
breakpoint('x', depth=1) # → стоп ('x',) {'depth': 1}
sys.breakpointhook = sys.__breakpointhook__
import os, subprocess, sys
env = dict(os.environ, PYTHONBREAKPOINT='0')
code = 'breakpoint(); print("дальше")'
r = subprocess.run([sys.executable, '-c', code], env=env,
capture_output=True, text=True, timeout=10)
print(r.stdout.strip()) # → дальше
See also
Open in the full glossarydocs.python.orgReport an inaccuracy