【问题标题】:VS Code Python Debugger "timed out waiting for debuggee to spawn"VS Code Python 调试器“等待被调试对象生成超时”
【发布时间】:2020-03-19 14:36:16
【问题描述】:

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

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)

我的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: Arquivo Atual",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal"
    }
]
}

【问题讨论】:

  • 你能分享你的代码吗...?请参阅:minimal reproducible example.
  • 当然。我相信问题不在于代码本身,它在没有调试器的情况下运行良好,但在这里:
  • 你能解释一下你的代码是做什么的吗?这些文件是什么样的?
  • 它应该计算第n个斐波那契数(从1开始)并将其列出在一个文件中。该文件只是一个简单的 .txt,只包含数字。代码检查文件是否已经存在,如果不存在,则使用前两个数字(1 和 2)创建一个文件。此外,如果第 n 个数字已经在文件中,则什么也不做。在我处理这段代码时,调试器停止工作。
  • 完全一样的事情发生在我身上。突然调试器开始显示“会话 1 超时等待调试对象生成”弹出窗口,几周后一切正常。

标签: python debugging visual-studio-code timeout


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    • 2020-12-16
    • 2020-11-07
    • 1970-01-01
    • 2020-04-14
    • 2020-09-30
    相关资源
    最近更新 更多