pudb调试python

写在最前面

Linux下运行python脚本,pudb是一个不错的调试器。尤其是,python多进程程序。

语法高亮,断点,调用栈,命令行都有

安装 

  • python2
sudo pip install pudb
  • python3
sudo pip3 install pudb

修改代码

  • 为需要调试的python代码,导入pudb。
from pudb.remote import set_trace
  • 在当前python脚本开头或需要调试的函数内,添加set_trace

运行调试

python -m pudb.run test.py

调试子进程

  • 当程序运行至子进程启动处,弹出如下提示
pudb:6899: Please telnet into 127.0.0.1 6899.
pudb:6899: Waiting for client...
  • 开启新终端,运行telnet命令:
telnet into 127.0.0.1 6899

此时,新终端出现调试界面,可以调试进入子进程程序。

调试命令

    Ctrl-p - edit preferences                                  # 编辑配置
                                                                                      
    n - step over ("next")                                     # 运行到下一行                       
    s - step into                                              # 运行进函数
    c - continue                                               # 继续运行
    r/f - finish current function                              # 结束当前函数
    t - run to cursor                                          # 运行到光标处
    e - show traceback [post-mortem or in exception state]     # 显示traceback

    H - move to current line (bottom of stack)                 # 移动到当前行(栈底)
    u - move up one stack frame                                # 移动到栈的上一行
    d - move down one stack frame                              # 移动到栈的下一行
                                                               
    o - show console/output screen                             # 显示命令行屏幕(回车返回pudb)

    b - toggle breakpoint                                      # 打断点/取消断点
    m - open module                                            # 打开python模块

    j/k - up/down                                              # 上/下
    Ctrl-u/d - page up/down                                    # 上一页/下一页
    h/l - scroll left/right                                    # 左滚动/右滚动
    g/G - start/end                                            # 跳转到首行/末行
    L - show (file/line) location / go to line                 # 跳到指定行
    / - search                                                 # 查找
    ,/. - search next/previous                                 # 查找下一个/上一个

    V - focus variables                                        # 聚焦在变量窗口
    S - focus stack                                            # 聚焦在栈窗口
    B - focus breakpoint list                                  # 聚焦在断点列表窗口
    C - focus code                                             # 聚焦在代码窗口
                      
    f1/?/H - show this help screen                             # 显示帮助窗口
    q - quit                                                   # 退出

    Ctrl-c - when in continue mode, break back to PuDB         # 当处于连续模式时,返回pudb

    Ctrl-l - redraw screen                                     # 重绘窗口
                                                                                      
Command line-related:                                          # 命令行相关
    ! - invoke configured python command line in current environment            # 进入命令行窗口
    Ctrl-x - toggle inline command line focus                                   # 切换命令行窗口和代码窗口

    +/- - grow/shrink inline command line (active in command line history)      # 增长/缩减命令行(命令行历史下激活)
    _/= - minimize/maximize inline command line (active in command line history)# 最小化/最大化命令行(命令行历史下激活)
                                                                                      
    Ctrl-v - insert newline                                    # 插入新行
    Ctrl-n/p - browse command line history                     # 浏览命令行历史
    Tab - yes, there is (simple) tab completion                # 快速补齐

Sidebar-related (active in sidebar):                           # 工具栏相关(工具栏激活时有效)
    +/- - grow/shrink sidebar                                  # 扩大/缩减工具栏(指的是工具栏宽度)
    _/= - minimize/maximize sidebar                            # 最小化/最大化工具栏
    [/] - grow/shrink relative size of active sidebar box      # 扩大/缩减激活工具栏相对大小(指的是窗口高度)
                  
Keys in variables list:                                        # 变量列表窗口的快捷键
    \ - expand/collapse                                        # 展开/收缩
    t/r/s/c - show type/repr/str/custom for this variable      # 切换type/repr/str/custom
    h - toggle highlighting                                    # 切换高亮
    @ - toggle repetition at top                               # 切换顶部重复
    * - cycle attribute visibility: public/_private/__dunder__ # 属性的循环可视化
    m - toggle method visibility                               # 切换方法的可见性
    w - toggle line wrapping                                   # 切换换行
    n/insert - add new watch expression                        # 添加新的watch表达式
    enter - edit options (also to delete)                      # 编辑选项

Keys in stack list:                                            # 栈列表窗口的快捷键

    enter - jump to frame                                      # 跳到某帧

Keys in breakpoints view:                                      # 断点列表窗口的快捷键

    enter - edit breakpoint                                    # 编辑断点
    d - delete breakpoint                                      # 删除断点
    e - enable/disable breakpoint                              # 启用/禁用断点

彩蛋
按上、下、左、右键,切换到不同的窗口

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

子建莫敌

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值