运行 VSCode 中的烧瓶每次都会导致 HTTPServer.serve_forever(self) 断点

Running flask in VSCode cause HTTPServer.serve_forever(self) breakpoint everytime

我已经创建了一个 Flask 应用程序并开始构建我的项目,但是当我在任何文件中使用断点进行调试时,vscode 将自动停止在 flask 默认模块中的这一行 HTTPServer.serve_forever(self)

事情很烦人,因为它会跳到这一行并忽略我原来的断点,让我很难调试。

有什么想法吗?

launch.json

{
    "name": "Python: Custom Flask",
    "type": "python",
    "request": "launch",
    "program": "${workspaceFolder}/venv/bin/activate",
    "module": "flask",
    "env": {
        "ENV": ".local"
    },
    "args": [
    "run",
    ]
}

serving.py

def serve_forever(self):
    self.shutdown_signal = False
    try:
        HTTPServer.serve_forever(self) # <- Always stop on this line
    except KeyboardInterrupt:
        pass
    finally:
        self.server_close()

app.py

from flask import app
app = Flask(__name__)

@app.route('/')
def index():
    return "OK"

app.run()

正在此处跟踪此问题:https://github.com/Microsoft/vscode-python/issues/2498

看起来问题已在 Python 插件的开发分支中得到解决,目前的解决方法是

you can continue debugging by selecting your thread in the "Call Stack" window. source