DebugUtil

PDB(命令行调试工具)

  • 进入命令行DEBUG模式

python -m pdb <python_file>

作用

命令行

打断点

b(break) 行号

查看帮助手册

h(help)

显示变量值

p(print)

退出debug

q(quit)

打印当前执行堆栈

w(where)

备注

PDB支持输入python语句,对于不认识的命令行,PDB会认为是python语句来执行),要显式表示该语句为python语句,可以在输入前加入 !

image-20210914104258430


NOTE

给当前文件的第3行打断点:b 3

给文件A的第15行打断点:b A:15


PDB++

安装后会默认替换PDB;加强版的特性包括:语法高亮、添加颜色

  • 安装

pip3 install pdbpp

py-spy(性能分析工具)

安装
pip3 install py-spy
生成火焰图
py-spy record -o profile.svg --pid <pid>
OR
py-spy record -o profile.svg -- python <file_name>
实时查看函数调用情况
py-spy top --pid <pid>
OR
py-spy top -- python <file_name>

pyroscope(性能分析工具)

待补充...

安装(for ubuntu)
wget https://dl.pyroscope.io/release/pyroscope_0.0.39_amd64.deb
sudo apt-get install ./pyroscope_0.0.39_amd64.deb
快速上手
export PYROSCOPE_SERVER_ADDRESS=http://<127.0.0.1:4040>
pyroscope exec python <python_file>
connect     Connect to an existing process and profile it
exec        Start a new process from arguments and profile it
help        Help about any command
server      Start pyroscope server. This is the database + web-based user interface
attach a process
pyroscope connect -pid {my-app-pid}

jupyter notebook

安装

现代版为JupyterLab,经典版为Jupyter Notebook

conda install -c conda-forge jupyterlab
jupyter-lab
conda install -c conda-forge notebook
jupyter-notebook

常用快捷键

img

img

拓展插件

conda install -c conda-forge jupyter_contrib_nbextensions jupyter_nbextensions_configurator