【问题标题】:VSCode cannot read user input while debugging a python code in integratedTerminal在集成终端中调试 python 代码时,VSCode 无法读取用户输入
【发布时间】:2020-12-06 02:48:32
【问题描述】:

在这段两行python代码中:

string = input("What's your name? ")

if string != '': print('Hello, ' + string + '!')

当我运行调试时,它会等待用户输入。输入名称后,终端(Python 调试控制台)就停在那里,print() 行永远不会被执行。 See the screenshot below

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",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

如果我在不调试的情况下运行此代码,一切正常。

注意:调试器之前工作正常。这个问题最近才发生。 非常感谢任何帮助或提示。

【问题讨论】:

  • 尝试删除断点
  • @eggheadlabs 由于调试功能是由python扩展提供的,您可以尝试禁用其他扩展并重新安装python扩展(或使用其他版本的python扩展)。参考:github.com/microsoft/vscode-python/issues/1125
  • @JillCheng 感谢您的建议。我已经将 python 扩展回滚到以前的版本(v2020.7.96456),然后问题就消失了,一切正常。在我看来,最新版本(v2020.8.101144)中引入了一个错误。我也尝试卸载并重新安装最新版本,但问题仍然存在。

标签: python debugging input visual-studio-code


【解决方案1】:

在我将python扩展回滚到之前的版本(v2020.7.96456)之后,问题就消失了,调试器可以前进到下一行代码,然后就可以正常工作了。

虽然我没有硬性证据证明为什么最新版本 (v2020.8.101144) 会导致调试器停止接受用户输入,但至少回滚到以前的版本可以作为临时补救措施,直到未来的修订版解决此问题。

【讨论】:

  • 谢谢!我整天都在为此苦苦挣扎。一旦我回滚 Python 扩展,问题就解决了。
  • 更新:VSCode 已在 Python 扩展的 v2020.8.1(2020 年 8 月 20 日)版本中修复了此终端输入问题。
猜你喜欢
  • 2019-10-30
  • 2016-08-09
  • 1970-01-01
  • 1970-01-01
  • 2020-03-26
  • 2021-05-26
  • 2021-10-06
  • 2019-06-12
  • 1970-01-01
相关资源
最近更新 更多