Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breakpoints are not hitting in VS Code while debugging Python Flask app #4355

Closed
iamshivprasad opened this issue Feb 12, 2019 · 6 comments
Closed
Assignees

Comments

@iamshivprasad
Copy link

iamshivprasad commented Feb 12, 2019

I'm new to Python Flask development and VS Code. I've been trying to create an app by referring the below tutorials.

https://code.visualstudio.com/docs/python/tutorial-flask

https://github.com/Microsoft/python-sample-vscode-flask-tutorial\

https://code.visualstudio.com/docs/python/debugging

Repo for reference: https://github.com/iamshivprasad/analytics

Cloned folder structure is:

  • Development
    • .vscode
      • launch.json
    • analyticspyengine
      • analytics_modules
      • controllers
      • datainterfaces
      • utils
      • init.py
      • analyticsservices.py
      • webapp.py
        .
        .
        .

I am able to launch the program successfully with below settings in launch.json.

 {
    "name": "Python: Flask",
    "type": "python",
    "request": "launch",
    "module": "flask",
    "env": {
        "FLASK_APP": "analyticspyengine.webapp",
        "FLASK_DEBUG": true,
        "FLASK_ENV": "development"
    },
    "args": [
        "run"
    ],
    "jinja": true
}

Content of webapp.py

#!/usr/bin/python3
import sys
from . import app   
from . import analyticsservices

Content of analyticspyengine/__init__.py

#!/usr/bin/python3
import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(__file__)))

from flask import Flask
app = Flask(__name__) 

I'm facing the following problems. Completely helpless and frustrated!!!

**1) Execution is not hitting any breakpoints

  1. After launching the app with the above settings, I'm not able to stop the service. i.e, Even after stopping the debugger, the app seems to be running. I can see the requests are being served through terminal output and Postman. The process seems to be alive until VS Code is closed.**

Is it an issue? Could someone shed some light?

Environment:
VS Code 1.31.0
Python Extension - 2019.1.0 (29 Jan 2019)
Python Version 3.7.1 64-bit
Flask Version 1.0.2
Windows 10

@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Feb 12, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Feb 12, 2019
@brettcannon
Copy link
Member

@iamshivprasad it looks like you stripped out "--no-debugger", "--no-reload" from "run". Try going back to the default and use the following (where all I did was change FLASK_APP):

{
            "name": "Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "analyticspyengine.webapp",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        }

@brettcannon brettcannon added the info-needed Issue requires more information from poster label Feb 15, 2019
@brettcannon
Copy link
Member

@iamshivprasad
Copy link
Author

@iamshivprasad it looks like you stripped out "--no-debugger", "--no-reload" from "run". Try going back to the default and use the following (where all I did was change FLASK_APP):

{
            "name": "Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "analyticspyengine.webapp",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        }

@brettcannon Thank you, I think this fixed my issue.

I have taken the config from one of my other apps where I don't face this issue. Surprisingly, I'm still not using these flags there and works perfectly fine. The difference between these two apps is the
way the app object is created (also, app.run(); I'm not using app.run() in the app where I face the issue)

I'm curious to know what exactly went wrong, if you can give a bit of insight. Also, I'd like to know the significance of these flags.

Once again, thank you for saving my day :)

@brettcannon
Copy link
Member

Glad it worked out!

@ghost ghost removed info-needed Issue requires more information from poster triage labels Feb 20, 2019
@brettcannon
Copy link
Member

And the flags basically turn off the automatic reload functionality of Flask which trips up our debugger. We're working on making them work together, but we're not quite there yet.

@iamshivprasad
Copy link
Author

@brettcannon Thank you.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants