Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have created a Flask app and start to build my project, but when I use breakpoint in any file for debugging, vscode will automatically stop at this line HTTPServer.serve_forever(self) in flask default module.

Thing is annoying since it will jump to this line and ignore my original breakpoint, make me hard to debug.

Any idea?

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()
like image 893
Brady Huang Avatar asked Nov 08 '22 02:11

Brady Huang


1 Answers

This issue is being tracked here: https://github.com/Microsoft/vscode-python/issues/2498

Looks like the issue is fixed in the development branch of the Python plugin and a workaround for now is

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

like image 131
givemesnacks Avatar answered Nov 14 '22 23:11

givemesnacks