VS Code Python 调试器“等待调试对象生成超时”

Ped*_*lia 8 python debugging timeout visual-studio-code

我的调试器甚至没有开始运行我的代码。我按 F5,调试选项卡打开,显示它正在加载,过了一会儿,它在弹出窗口中显示“Session-1 等待调试对象生成超时”。我使用的是 VS Code 版本 1.40.1,我设置了虚拟环境,并且调试器可以正常工作,在断点处停止并更改屏幕底部蓝色条的颜色。在扰乱 open() 函数时出现问题,但调试器无法处理任何文件。我已经看到并尝试了此处此处提供的解决方案。我不使用 Conda、Jupyter 或标准 Python 扩展之外的任何扩展。代码:

import os
def fib(n):
    if not os.path.exists("Fibfile.txt"):
        with open("Fibfile.txt", "w") as file:
            file.write("1\n2\n")
    with open("Fibfile.txt", "r") as file:
        contents = file.readlines()
        data = []
        for item in contents:
            # removes newline
            data.append(int(item[:-1]))
    with open("Fibfile.txt", "a") as file:
        if n <= len(data):
            return
        else:
            while n > len(data):
                data.append(data[-2]+data[-1])
                file.write(f"{data[-1]}\n")
fib(100)
Run Code Online (Sandbox Code Playgroud)

我的启动.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: Arquivo Atual",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal"
    }
]
}
Run Code Online (Sandbox Code Playgroud)

zhl*_*luo 4

我的解决方案是降级 Visual Studio Code 的 Python 扩展。您可以从GitHub 发布下载。PTVSD 版本 2019.10.44104 适用于 VS Code 1.40.2。未选中的扩展:自动更新/自动检查更新并从 VSIX 手动安装。

更新:较新版本的 VS Code 1.41 已修复此问题。