我在VS代码中进行了Python调试。 以下是launch.json文件:
{
// 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": "Python: Current File",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"python": "${command:python.interpreterPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions":[
"RedirectOutput"
],
"console": "integratedTerminal"
}
]
}
以下是settings.json文件:
{
"python.pythonPath": "c:\\Users\\susan\\Documents\\PythonScripts\\venv\\Scripts\\python.exe",
// to fix 'Timeout waiting for debugger connections'
"python.terminal.activateEnvironment" : false
}
当我在 VS code 中调试 python 脚本时,我得到了
Time out waiting for launcher to connect
并且无法调试 python 脚本。
我可以知道如何解决这个问题吗?
非常简单。打开
launch.json
文件并将以下内容添加到其中:
{
"name": "Python: Debug Console",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole"
}
然后保存退出。无论您做什么,都不要清除其中已有的文本,否则可能会使情况变得更糟
如果出于某种原因“internalConsole”不是一个好的解决方案:
在你的 shell 脚本中:
export PROCESS_SPAWN_TIMEOUT=30
或者直接破解代码(如果更新扩展程序将恢复):
.vscode-server/extensions/ms-python.python-2022.18.2/pythonFiles/lib/python/debugpy/adapter/launchers.py[161]:
改变:
timeout=(None if sudo else common.PROCESS_SPAWN_TIMEOUT)
至:
timeout=30,
可能是本地主机上到 python 调试器的连接被防火墙阻止了!