Python Debugging

Tracebacks, breakpoints, and profiling to fix bugs fast.

  • python debug
  • breakpoint pdb
  • traceback
  • cprofile
  • logging

Python Debugging

Tracebacks, breakpoints, and profiling to fix bugs fast.

Commands

CommandWhat it does
python -X dev app.pyDev mode: extra warnings
breakpoint()Built-in debugger (pdb)
python -m pdb app.pyDebugger from the start
cProfile cumulative runFind hot functions
traceback.print_exc()Log full stack in except blocks

Example

try:
    main()
except Exception:
    import traceback; traceback.print_exc()
    breakpoint()

FAQ

How do I inspect a crashing prod process?

Log tracebacks with structlog/logging plus request IDs; reproduce locally under pdb from the logged input.

print vs logging?

logging with levels and handlers; print debugging never survives to production.

Câu hỏi thường gặp

How do I inspect a crashing prod process?
Log tracebacks with structlog/logging plus request IDs; reproduce locally under pdb from the logged input.
print vs logging?
logging with levels and handlers; print debugging never survives to production.

Python