brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: PYTHONBREAKPOINT decides what a python breakpoint() call does

Python
~/tips/tip-python-pythonbreakpoint-env-var

PYTHONBREAKPOINT=0 python3 app.py

Switches or disables breakpoint() calls without editing the source.

I leave breakpoint() calls in while I work, and the environment variable controls them.

PYTHONBREAKPOINT=0 python3 app.py
PYTHONBREAKPOINT=ipdb.set_trace python3 app.py

breakpoint() calls whatever PYTHONBREAKPOINT names. Without the variable it opens pdb. The value 0 turns every call into a no-op, which is a safe way to run a program that still contains a forgotten one. A dotted path such as ipdb.set_trace or pudb.set_trace switches debuggers, as long as that package is installed. Still remove stray calls before you ship, since the variable can be set differently in production.

Further reading: breakpoint() in the built-in functions reference

More Python tips import asyncio from enum import StrEnum, auto except* ValueError as eg: import pytest pytest --maxfail=2 All Python tips (107) All topics

Link