当前位置: 首页 > news >正文

VSCode优雅的使用debug

原始用法:(这里不使用)

配置launch.json,里面传入参数然后debug,这里我们通常需要传入的参数比较多,而且经常修改参数,直接去修改launch.json会比较麻烦,所以使用sh脚本比较方便。

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "image_demo.py",
            "type": "debugpy",
            "request": "launch",
            "program": "demo/image_demo.py",
            "console": "integratedTerminal",
            "justMyCode": false,
            "args": [
                "demo/demo.jpg",
                "my_configs/mobilenetv2_8xb24-ms-416-300e_coco.py",
                "--weight","checkpoints/yolov3_mobilenetv2_mstrain-416_300e_coco_20210718_010823-f68a07b3.pth",
                "--out-dir","outputs"  
            ]
        }
    ]
}

(优雅的用法)直接使用sh文件命令运行debug

1. 安装

  1. 安装包 pip install debugpy -U
  2. 安装vscode关于python的相关插件

2. 创建sh文件

文件内容如下:train.sh

python tools/train.py my_configs/ssdlite_mobilenetv2-scratch_8xb24-600e_coco.py

修改文件权限,变成可运行的文件。

chmod +x train.sh

3. 在python代码里面(最前面加上这句话)

在这里插入图片描述

import debugpy
try:
    # 5678 is the default attach port in the VS Code debug configurations. Unless a host and port are specified, host defaults to 127.0.0.1
    debugpy.listen(("localhost", 9501))
    print("Waiting for debugger attach")
    debugpy.wait_for_client()
except Exception as e:
    pass

4. 在vscode的launch.json的configuration里面,加上这个配置

在这里插入图片描述

{
            "name": "sh_file_debug",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 9501
            }
        },

🚨 上面的端口号都写一样。别搞错了。

5. 运行sh脚本

例如 ./train.sh
这里我们会看到Waiting for debugger attach,这时候我点击下面图片中左上角的运行按钮,对应我们上面"name": “sh_file_debug”,这个的名称,这样就进入Debug,我们要传入的参数都在sh脚本里面,然后就愉快的代码调试。

在这里插入图片描述

相关文章:

  • QML面试笔记--UI设计篇04交互控件
  • 虚幻基础:碰撞帧运算
  • 【13】数据结构之树结构篇章
  • AI自动化制作web和手机应用软件的利器:bolt.new
  • Python设计模式:策略模式
  • 主机协议端口安全
  • 网络问题之TCP/UDP协议
  • 【Windows自带的图片查看软件photo】
  • 回文日期2
  • Process Explorer 性能调优实战:精准定位资源泄漏与高负载进程
  • ZYNQ笔记(五):AXI GPIO 中断
  • C++指针(四)万字图文详解!
  • 【特权FPGA】之乘法器
  • P8623 [蓝桥杯 2015 省 B] 移动距离
  • go学习记录(第一天)
  • 一、TorchRec里边的输入输出类型
  • 为什么要将函数变量化?
  • django rest framework相关面试题
  • windows+cmake+vscode+NDK远程调试安卓端C++项目
  • 回文日期1
  • 建设网站目的及功能定位是什么/seo怎么刷关键词排名
  • 大连网站排名/互动营销是什么意思
  • phpcms v9 网站建设设计制作网络科技模板/免费b站推广网站在线
  • 天津武清做网站/创建网站平台
  • iis 7.5 网站/网络营销能干什么工作
  • php做网站主要怎么布局/企业微信营销管理软件