跳转至

1.远程调试

源码

Python
import datetime
import ptvsd
import sys

# Enable the debugger to attach to the process
ptvsd.enable_attach(address=('0.0.0.0', 5678))

# Pause the execution until a debugger is attached
ptvsd.wait_for_attach()

print("python版本:", sys.version)
now = datetime.datetime.now()
print("当前时间:", now.strftime("%Y-%m-%d %H:%M:%S"))
  • 说明

    使用ptvsd库来进行python远程调试,上位机IDE为Visual Studio Code,按F9将断点打在print所在行,安装完python插件后,按F5即可启动调试。

下面是vsCode的launch.json示例:

JSON
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "192.168.11.177",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "/data/project/"
                }
            ],
            "justMyCode": true
        }
    ]
}