Debug in Python3
This document introduces 2 simple methods to debug Python code.
1. pdb
add breakpoint()
# some python code
breakpoint()
# some python code
support option
where
up
down
step
nexe
continue
quit
run with pdb
python3 -m pdb -c continue <program path>
2. cProfile
python3 -m cProfile simul.py
python3 -m cProfile -s tottime simul.py
python3 -m cProfile -o prof.out simul.py
from simul import benchmark
import cProfile
cProfile.run("benchmark()")
pr = cProfile.Profile()
pr.enable()
benchmark()
pr.disable()
pr.print_stats()
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here