question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to debug flask after recent vscode upgrade

See original GitHub issue

Environment data

  • VS Code version: 1.27.1
  • Extension version (available under the Extensions sidebar): 2018.8.0
  • OS and version: macOS 10.13.6
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.5
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): none
  • Relevant/affected Python packages and their versions: flask 1.0.2

Actual behavior

Breakpoint stops serving.py in the function serve_forever on line 612.

Expected behavior

Breakpoint should stop in my code on the line I set it. In this case it should be line 6 of app.py

Steps to reproduce:

  1. create the following file app.py
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"
  1. start the application using the default launch configuration for flask in vs code
  2. add a breakpoint on line 6 of app.py
  3. start a browser and enter http://localhost:5000/
  4. See how it breaks at the wrong location

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Starting Jedi Python language engine.
##########Linting Output - pylint##########

--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

bug/> cd /Users/stephengibson/Documents/github.ibm.com/bug ; env "FLASK_APP=app.py" "PYTHONIOENCODING=UTF-8" "PYTHONUNBUFFERED=1" "PYTHONPATH=/Users/stephengibson/.vscode/extensions/ms-python.python-2018.8.0/pythonFiles/experimental/ptvsd" /usr/local/bin/python3 -m ptvsd --host localhost --port 52628 -m flask run --no-debugger --no-reload
 * Serving Flask app "app.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dungeontigercommented, Sep 12, 2018

@jchang10 @DonJayamanne Thanks. That’s exactly the issue. It seems to stop on the Main Thread but when I switch to the thread running my code I’m able to debug appropriately. I greatly appreciate the workaround.

I suppose you can close this issue as a duplicate.

screenshot 2018-09-12 16 31 13

0reactions
MandarJKulkarnicommented, Sep 17, 2018

After upgrading ptvsd to 4.1.2, unable to debug anything, neither flask nor ‘current file’ debugging is working.

Getting error “C:\Python27\python.exe: No module named ptvsd.main; ‘ptvsd’ is a package and cannot be directly executed”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to debug Flask app in Visual Studio Code
I have a currently working flask app. I want to debug it in Visual Studio Code. I keep hitting errors that I can't...
Read more >
Python and Flask Tutorial in Visual Studio Code
Python Flask tutorial showing IntelliSense, debugging, and code navigation support in Visual Studio Code, the best Python IDE.
Read more >
How to Debug Flask Applications in VS Code
This article lays out a simple step-by-step guide that will enable you to complete the set-up and configuration to easily debug flask apps....
Read more >
Debugging Flask App with Visual Studio Code IDE - YouTube
In this tutorial we will see how to Debug a Flask Python Application using Visual Studio Code IDE.If you want to read through, ......
Read more >
Debug Python code - Visual Studio (Windows) - Microsoft Learn
Visual Studio Code. Visual Studio provides a comprehensive debugging experience for Python, including attaching to running processes, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found