vscode local attach debug配置与使用

本文介绍如何使用VSCode进行PyTorch源码的调试。通过在Python代码中加入特定指令,配合launch.json配置文件,实现对指定端口和主机的远程调试附着。此方法适用于解决attachusingprocessID类型调试时遇到的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

配置debug

用vscode打开pytorch源码,run侧边栏中新建launch.json
在这里插入图片描述
选择attach using process ID类型 的上面那个remote attach(因为我尝试了attach process id总是搞不定。。)
在这里插入图片描述
配置好port和host,再在python代码中加入
在这里插入图片描述
此时执行便会等待attach:

(pytorch) xueruini@nico2:~/onion_rain/pytorch/object_detection$ python train.py --json experiments/thyroid_v4_train.json --device 0,1 --debug
47592
Waiting for debugger attach at 127.0.0.1:12345 ......
train.py:226: DeprecationWarning: 'redirect_output' setting via enable_attach will be deprecated in the future versions of the debugger. This can be set using redirectOutput in Launch config in VS Code, using Tee output option in Visual Studio, or debugOptions configuration for any client.
  ptvsd.enable_attach(address=(host, port), redirect_output=True)

此时选择remote attach即可进行debug
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值