microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.28k stars 1.17k forks source link

VS Code doesn't run the project if there is Python Debug Console opened already #9663

Closed saasforge closed 4 years ago

saasforge commented 4 years ago

Environment data

Expected behaviour

When I have a project and would like to run it and hit F5 the VS Code opens or reuses (if already opened, I don't know which behavior is default one) Python Debug Console and shows output there.

Actual behaviour

When I hit F5, if there is already Python Debug Console opened, it does nothing and will end up the timeout error (Timeout waiting for debugger connection). ONLY if I close console it will reopen it and run the project there.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

Open any Flask project, select Python interpreter, and run it. The first time it will work. But on the second time, it will not.

Settings.json

{
    "python.pythonPath": "venv\\Scripts\\python.exe"
}

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: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "application.py",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload",
                "--port=5002"
            ],
            "jinja": true,
            "console": "integratedTerminal"
        }
    ]
}
ericsnowcurrently commented 4 years ago

Hi @saasforge. Thanks for getting in touch with us. This is definitely not something that should be happening to you. Let's see if we can figure out the problem.

First of all, I was not able to reproduce the problem you described. Here's what I did:

  1. create a new project folder and open in in vscode
  2. create the launch.json exactly as you provided above.
  3. create a new venv in ${workspaceRoot}/.venv (and run .venv/bin/python3 -m pip install flask)
  4. select that env
  5. create an application.py file (see below)
  6. hit F5

At that point it started debugging and everything worked fine.

Here's the text of the app file I used:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World'

I also tried opening the "DEBUG CONSOLE" panel before hitting F5. However, it did not make a difference.

ericsnowcurrently commented 4 years ago

One thing that would help is if you included logs. There are two. Please provide the content of the "Python" output panel. Also, please provide the content of the "developer tools console" (in the Help menu click on "Toggle Developer Tools"; then in the panel that pops up click on "console").

ericsnowcurrently commented 4 years ago

Also note that I am not on WIndows. However, I'm not sure yet that matters.

saasforge commented 4 years ago

Thanks for your respond!

Hi @saasforge. Thanks for getting in touch with us. This is definitely not something that should be happening to you. Let's see if we can figure out the problem.

First of all, I was not able to reproduce the problem you described. Here's what I did:

1. create a new project folder and open in in vscode

2. create the launch.json exactly as you provided above.

3. create a new venv in `${workspaceRoot}/.venv` (and run `.venv/bin/python3 -m pip install flask`)

4. select that env

5. create an application.py file (see below)

6. hit F5

At that point it started debugging and everything worked fine.

Here's the text of the app file I used:

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World'

I also tried opening the "DEBUG CONSOLE" panel before hitting F5. However, it did not make a difference.

I did exactly as you described and it worked nicely. But it's still not working with my project that I didn't create from scratch. So, something wrong is with my projects but I can't figure out what exactly it is.

I was trying to provide logs. The first log is empty because when I try to debug it just does nothing and there is nothing in the output panel.

As for debugging tool there is something:

  ERR timeout after 500 ms: Error: timeout after 500 ms
    at t.RawDebugSession.handleErrorResponse (file:///C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2821:819)
    at file:///C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2821:250
    at async t.RawDebugSession.shutdown (file:///C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2819:336)
    at async R.terminate (file:///C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:5113:637)

And also warning:

linesLayout.ts:265 Commiting pending changes before change accessor leaves due to read access.

dom.ts:216 [Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
v @ dom.ts:216
b @ dom.ts:237
_setListeningToMouseWheel @ scrollableElement.ts:320
S @ scrollableElement.ts:219
t.SmoothScrollableElement @ scrollableElement.ts:507
a @ editorScrollbar.ts:58
W @ viewImpl.ts:143
_createView @ codeEditorWidget.ts:1484
_attachModel @ codeEditorWidget.ts:1385
setModel @ codeEditorWidget.ts:422
setInput @ textFileEditor.ts:142
processTicksAndRejections @ internal/process/task_queues.js:89
dom.ts:216 [Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
saasforge commented 4 years ago

What I also noticed the output when it's working is different for 2 projects:

A "good" project:

(venv) c:\temp\FlaskTest>cd c:\temp\FlaskTest && cmd /C "set "FLASK_APP=application.py" && set "FLASK_ENV=development" && set "FLASK_DEBUG=0" && set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\Seacat\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 12176 -m flask run --no-debugger --no-reload --port=5002 "
 * Serving Flask app "application.py"
 * Environment: development
 * Debug mode: off
 * Running on http://127.0.0.1:5002/ (Press CTRL+C to quit)

End of the activation.bat:

set "PATH=%VIRTUAL_ENV%\Scripts;%PATH%"

set FLASK_APP=application

:END

A "bad" one:

d:\Projects\SaaSForge\Code\n>d:/Projects/SaaSForge/Code/venv/Scripts/activate.bat
(venv) d:\Projects\SaaSForge\Code>d:\Projects\SaaSForge\Code\venv\Scripts\python.exe c:\Users\user\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 13062 -m flask run --no-debugger --no-reload --port=5002
 * Serving Flask app "application"
 * Environment: development
 * Debug mode: off
 * Running on http://127.0.0.1:5002/ (Press CTRL+C to quit)

I don't know if it's important though.

ericsnowcurrently commented 4 years ago

I did exactly as you described and it worked nicely. But it's still not working with my project that I didn't create from scratch. So, something wrong is with my projects but I can't figure out what exactly it is.

Yeah, it definitely sounds like something is not working right with your project. Let's try to figure that out. It could still be something related to the extension.

The first log is empty because when I try to debug it just does nothing and there is nothing in the output panel.

There should definitely be something in the "Python" output panel. In the "View" menu click on "Output". In that panel, click on the pull-down menu toward the right side (it probably says "Tasks"). In that list select "Python". Please provide the contents.

For example, in my case the "Python" output panel starts with the following:

User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'

As for debugging tool there is something:

Don't worry about the error and warning you saw in the developer tools console. I don't think they are related.

What I also noticed the output when it's working is different for 2 projects:

First, let's be sure we're comparing apples-to-apples:

I have some more questions:

Regarding the comparison between the "good" and "bad" examples, here is what I noticed as different:

What there anything else? If anything there is a problem then it's probably the second one. However, I'm not sure even that is the problem. When I run my example, I see the following in the "Python Debug Console" TERMINAL panel:

$ .../test_projects/gh-9663/.venv/bin/python3.7 .../.vscode-insiders/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/new_ptvsd/wheels/ptvsd/launcher -m flask run --no-debugger --no-reload --port=5002 
source .../test_projects/gh-9663/.venv/bin/activate
 * Serving Flask app "application.py"
 * Environment: development
 * Debug mode: off
 * Running on http://127.0.0.1:5002/ (Press CTRL+C to quit)

(Note that there are no environment variables explicitly set.)

FYI, my "DEBUG CONSOLE" panel (not the TERMINAL panel) is empty.

saasforge commented 4 years ago

Yeah, it definitely sounds like something is not working right with your project. Let's try to figure that out. It could still be something related to the extension.

Thanks!

The first log is empty because when I try to debug it just does nothing and there is nothing in the output panel.

There should definitely be something in the "Python" output panel. In the "View" menu click on "Output". In that panel, click on the pull-down menu toward the right side (it probably says "Tasks"). In that list select "Python". Please provide the contents.

Okay, I see now.

User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'DebugAdapterFactory - experiment'
> conda --version
> python3.7 -c "import sys;print(sys.executable)"
> pyenv root
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> py -3.7 -c "import sys;print(sys.executable)"
> py -3.6 -c "import sys;print(sys.executable)"
> py -3 -c "import sys;print(sys.executable)"
> py -2 -c "import sys;print(sys.executable)"
> d:\Projects\SF\Code\project\venv\Scripts\python.exe -c "import sys;print(sys.executable)"
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python36\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python36\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> D:\Python332\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> D:\Python332\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda2\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda2\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> conda info --json
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> ~\.virtualenvs\clean-bill-O2n0Wi26\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> ~\.virtualenvs\clean-bill-O2n0Wi26\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
Starting Jedi Python language engine.
> conda --version
> d:\Projects\SF\Code\project\venv\Scripts\python.exe -c "import sys;print(sys.prefix)"
cwd: d:\Projects\SF\Code\project
> d:\Projects\SF\Code\project\venv\Scripts\python.exe -c "import sys;print(sys.prefix)"
cwd: d:\Projects\SF\Code\project
> d:\Projects\SF\Code\project\venv\Scripts\python.exe -c "import sys;print(sys.executable)"
cwd: d:\Projects\SF\Code\project
> d:\Projects\SF\Code\project\venv\Scripts\python.exe -c "import sys;print(sys.executable)"
cwd: d:\Projects\SF\Code\project
> d:\Projects\SF\Code\project\venv\Scripts\python.exe -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: d:\Projects\SF\Code\project
> d:\Projects\SF\Code\project\venv\Scripts\python.exe -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: d:\Projects\SF\Code\project
> d:\Projects\SF\Code\project\venv\Scripts\python.exe -m site --user-site
cwd: d:\Projects\SF\Code\project
> d:\Projects\SF\Code\project\venv\Scripts\python.exe -m site --user-site
cwd: d:\Projects\SF\Code\project
> d:\Projects\SF\Code\project\venv\Scripts\python.exe completion.py
cwd: c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles
> d:\Projects\SF\Code\project\venv\Scripts\python.exe completion.py
cwd: c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles
> conda env list
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python36\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python36\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> d:\Projects\SF\Code\project\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> d:\Projects\SF\Code\project\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py

First, let's be sure we're comparing apples-to-apples:

* is settings.json the same for both?

Yes. It's:

{
    "python.pythonPath": "venv\\Scripts\\python.exe"
}
* is launch.json the same for both?

Yes, the same as I started this issue with.

* what is in the "Python" output panel for the "good" project?  (so we can compare with the log from the "bad" one)
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'DebugAdapterFactory - experiment'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> py -3.7 -c "import sys;print(sys.executable)"
> py -3.6 -c "import sys;print(sys.executable)"
> py -3 -c "import sys;print(sys.executable)"
> py -2 -c "import sys;print(sys.executable)"
> c:\temp\FlaskTest\venv\Scripts\python.exe -c "import sys;print(sys.executable)"
> conda info --json
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
Starting Jedi Python language engine.
> ~\.virtualenvs\clean-bill-O2n0Wi26\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> ~\.virtualenvs\clean-bill-O2n0Wi26\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python36\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python36\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Python27\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Python27\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Python27\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Python27\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> D:\Python332\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> D:\Python332\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda3\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> conda --version
> c:\temp\FlaskTest\venv\Scripts\python.exe -c "import sys;print(sys.prefix)"
cwd: c:\temp\FlaskTest
> c:\temp\FlaskTest\venv\Scripts\python.exe -c "import sys;print(sys.prefix)"
cwd: c:\temp\FlaskTest
> c:\temp\FlaskTest\venv\Scripts\python.exe -c "import sys;print(sys.executable)"
cwd: c:\temp\FlaskTest
> c:\temp\FlaskTest\venv\Scripts\python.exe -c "import sys;print(sys.executable)"
cwd: c:\temp\FlaskTest
> c:\temp\FlaskTest\venv\Scripts\python.exe -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: c:\temp\FlaskTest
> c:\temp\FlaskTest\venv\Scripts\python.exe -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: c:\temp\FlaskTest
> c:\temp\FlaskTest\venv\Scripts\python.exe -m site --user-site
cwd: c:\temp\FlaskTest
> c:\temp\FlaskTest\venv\Scripts\python.exe -m site --user-site
cwd: c:\temp\FlaskTest
> C:\Development\Anaconda2\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Anaconda2\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> conda env list
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python35-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python36\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python36\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Development\Python37-64\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Python27\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> C:\Python27\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\interpreterInfo.py
> c:\temp\FlaskTest\venv\Scripts\python.exe completion.py
cwd: c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles
> c:\temp\FlaskTest\venv\Scripts\python.exe completion.py
cwd: c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles
* is flask the same version in both venvs?

I have some more questions:

* where are you seeing the output that you provided (that says for example, `(venv) c:\temp\FlaskTest>...`)?  (I'm guessing it's the "Python Debug Console" terminal panel.  Is that right?)

Yes, it's from Python Debug Console

* by "activation.bat" do you mean `c:\temp\FlaskTest\venv\Scripts\activate.bat`?

Yes, sorry I used the wrong name, it's activate.bat

* do you know what added `set FLASK_APP=application` to activation.bat?

Yes, I do, it was me!

* does `d:/Projects/SaaSForge/Code/venv/Scripts/activate.bat` not have that line?

It does.

* what happens if you run flask manually for both (after activating the venvs)?

They both are running okay (without env vars) in the same terminal (unlike when I hit Debug it always opens a new Python Debug Console or reuse if it's already open - for a good project; bad project, if Python Debug Console, just "does nothing" and then shows the timeout error - all about Debug).

  * with env vars: `cmd /C "set "FLASK_APP=application.py" && set "FLASK_ENV=development" && set "FLASK_DEBUG=0" && set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && <workspace root>\venv\Scripts\python.exe -m flask run --no-debugger --no-reload --port=5002 "`
  * without env vars: `<workspace root>\venv\Scripts\python.exe -m flask run --no-debugger --no-reload --port=5002`

I was not able to run them using the first command with vars, I don't know why, when I entered it and hit enter, it just did nothing.

Regarding the comparison between the "good" and "bad" examples, here is what I noticed as different:

* "good" example explicitly changes to what I'm guessing is the workspace root (though it is already in that directory)

Not sure what you mean.

* "good" example sets a number of environment variables while the "bad" one doesn't set any

  * "FLASK_APP=application.py"
  * "FLASK_ENV=development"
  * "FLASK_DEBUG=0"
  * "PYTHONIOENCODING=UTF-8"
  * "PYTHONUNBUFFERED=1"

No, actually the good project has only one env var specified in activate.bat, FLASK_APP, others are probably from launch.json. But for some reason the bad project doesn't show them when runs.

* different debugger ports -- working: 12176; not: 13062 (unlikely to be related to the problem)

The port is different every time when I run any project.

* (guessing) "FLASK_APP" line in "activation.bat" in "good" example

This line is in both projects.

What there anything else? If anything there is a problem then it's probably the second one. However, I'm not sure even that is the problem. When I run my example, I see the following in the "Python Debug Console" TERMINAL panel:

$ .../test_projects/gh-9663/.venv/bin/python3.7 .../.vscode-insiders/extensions/ms-python.python-2020.1.58038/pythonFiles/lib/python/new_ptvsd/wheels/ptvsd/launcher -m flask run --no-debugger --no-reload --port=5002 
source .../test_projects/gh-9663/.venv/bin/activate
 * Serving Flask app "application.py"
 * Environment: development
 * Debug mode: off
 * Running on http://127.0.0.1:5002/ (Press CTRL+C to quit)

(Note that there are no environment variables explicitly set.)

FYI, my "DEBUG CONSOLE" panel (not the TERMINAL panel) is empty.

My debug consoles are empty too.

saasforge commented 4 years ago

Okay, I also see some confusion with terms. When I said "Python Debug Console" I meant terminal with "Python Debug Console" selected in the dropdown on the right, not the Debug Console besides Output and Terminal. Please let me know if I confused you completely.

ericsnowcurrently commented 4 years ago

Regarding the comparison between the "good" and "bad" examples, here is what I noticed as different:

  • "good" example explicitly changes to what I'm guessing is the workspace root (though it is already in that directory)

Not sure what you mean.

By this I meant that it is explicitly changing directories (cd c:\temp\FlaskTest). However, I doubt that's important.

ericsnowcurrently commented 4 years ago

Thanks for the info, @saasforge. That's really helpful. Some of it isn't particularly informative about the problem but the following is:

  • with env vars: cmd /C "set "FLASK_APP=application.py" && set "FLASK_ENV=development" && set "FLASK_DEBUG=0" && set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && <workspace root>\venv\Scripts\python.exe -m flask run --no-debugger --no-reload --port=5002 "
  • without env vars: <workspace root>\venv\Scripts\python.exe -m flask run --no-debugger --no-reload --port=5002

I was not able to run them using the first command with vars, I don't know why, when I entered it and hit enter, it just did nothing.

This indicates that debugging doesn't work without the env vars from the launch config, which makes sense.

Note that in VS Code, the first time the debugger starts it creates the "Python Debug Console" terminal and provides those env vars silently. If that terminal already exists then it passes them explicitly. So that probably explains the difference. If you close that terminal and then try debugging with the "good" example, do you still see the env vars in the command in the new "Python Debug Console" terminal? I would expect not.

ericsnowcurrently commented 4 years ago

As to the problem, the "bad" example works fine if there is no "Python Debug Console" terminal already, right? When there is one and you hit F5, does a command get written to that terminal?

Also, before hitting F5, can you verify that the terminal is at a prompt. It may be that flask is still running there, even though the debugger in VS Code thinks it stopped. That would match what you are seeing.

saasforge commented 4 years ago

Thanks for the info, @saasforge. That's really helpful. Some of it isn't particularly informative about the problem but the following is:

  • with env vars: cmd /C "set "FLASK_APP=application.py" && set "FLASK_ENV=development" && set "FLASK_DEBUG=0" && set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && <workspace root>\venv\Scripts\python.exe -m flask run --no-debugger --no-reload --port=5002 "
  • without env vars: <workspace root>\venv\Scripts\python.exe -m flask run --no-debugger --no-reload --port=5002

I was not able to run them using the first command with vars, I don't know why, when I entered it and hit enter, it just did nothing.

This indicates that debugging doesn't work without the env vars from the launch config, which makes sense.

Note that in VS Code, the first time the debugger starts it creates the "Python Debug Console" terminal and provides those env vars silently. If that terminal already exists then it passes them explicitly. So that probably explains the difference. If you close that terminal and then try debugging with the "good" example, do you still see the env vars in the command in the new "Python Debug Console" terminal? I would expect not.

That's interesting. I closed the Python Debug Console and rerun debugging:


c:\temp\FlaskTest>c:/temp/FlaskTest/venv/Scripts/activate.bat
(venv) c:\temp\FlaskTest>c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 64442 -m flask run --no-debugger --no-reload --port=5002
 * Serving Flask app "application"
 * Environment: development
 * Debug mode: off
 * Running on http://127.0.0.1:5002/ (Press CTRL+C to quit)

It didn't show env variables, but the next time it did:

(venv) c:\temp\FlaskTest>cd c:\temp\FlaskTest && cmd /C "set "FLASK_APP=application.py" && set "FLASK_ENV=development" && set "FLASK_DEBUG=0" && set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && c:\temp\FlaskTest\venv\Scripts\python.exe c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 64538 -m flask run --no-debugger --no-reload --port=5002 "
 * Serving Flask app "application.py"
 * Environment: development
 * Debug mode: off
 * Running on http://127.0.0.1:5002/ (Press CTRL+C to quit)

It's all for a "good project" as the "bad project" is not working this way.

saasforge commented 4 years ago

As to the problem, the "bad" example works fine if there is no "Python Debug Console" terminal already, right? When there is one and you hit F5, does a command get written to that terminal?

Yes, but only once. Every time after I stop debugging I have to close the Python Debug Console before hitting F5 as for the debugging is not working when it's already open.

Also, before hitting F5, can you verify that the terminal is at a prompt. It may be that flask is still running there, even though the debugger in VS Code thinks it stopped. That would match what you are seeing.

Not sure what you mean, can you clarify what exactly I should do? Thanks.

ericsnowcurrently commented 4 years ago

Not sure what you mean, can you clarify what exactly I should do?

  1. start debugging with the "bad" example
  2. stop debugging
  3. check the "Python Debug Console" terminal to see if it has returned to a shell prompt or if flask is still running
saasforge commented 4 years ago

Not sure what you mean, can you clarify what exactly I should do?

1. start debugging with the "bad" example

2. stop debugging

3. check the "Python Debug Console" terminal to see if it has returned to a shell prompt or if flask is still running

Okay, when I stop debugging the "bad" project it looks like it stopped the Python Debug Console because I see:

... many others requests here
127.0.0.1 - - [27/Jan/2020 11:17:12] "GET /auth/login HTTP/1.1" 200 -
127.0.0.1 - - [27/Jan/2020 11:17:14] "GET /static/dist/auth.bundle.js HTTP/1.1" 200 -
127.0.0.1 - - [27/Jan/2020 11:17:17] "GET /static/media/logo.png HTTP/1.1" 304 -

(venv) d:\Projects\SaaSForge\Code\project>

But if I try to start it again it can't start for some reason until I close the Python Debug Console terminal.

ericsnowcurrently commented 4 years ago

Well, that certainly leaves us with more questions then. Is there a repo you can point me at for the "bad" example. I'd like to see if it gives me trouble too. Thanks!

saasforge commented 4 years ago

Yes, for example, it's my repo https://github.com/saasforge/open-source-saas-boilerpate But I'm not sure what's the problem - code itself or the settings. The thing is the "bad" projects not always were "bad" - they were good until some point and then, suddenly, all my Flask projects, one by one, became "bad". Thanks for your efforts!

ericsnowcurrently commented 4 years ago

Thanks @saasforge. I set everything up with that repo the way you described (repo, python 3.6, launch.json, venv with all requirements installed). However, it works fine for me. I made sure to visit the app in my browser.

I have some questions:

Note that to stop the debugging session I could not hit Ctrl-C in the terminal. Instead I had to use the VS Code stop button. However, I don't think that matters.

Also, I did notice that your launch.json is slightly different from the default, which looks like this:

{
    // 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: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "application.py",
                "FLASK_ENV": "development",
                "FLASK_DEBUG": "0"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        }
    ]
}

Yours has a "--port=5002" arg, as well as a "console": "integratedTerminal" setting. However, I didn't have any trouble using your launch.json, so I don't think that is related.

saasforge commented 4 years ago

Thanks @saasforge. I set everything up with that repo the way you described (repo, python 3.6, launch.json, venv with all requirements installed). However, it works fine for me. I made sure to visit the app in my browser.

I have some questions:

* are you editing this locally or in docker? (I noticed the Dockerfile)

No, I don't (although the project has dockerfile I don't use it).

* are you setting any breakpoints? (setting breakpoints did not make a difference for me)

Do you mean if I have some breakpoints? Sometimes yes when it's necessarily bit I didn't see any difference with running terminal.

* are you using a database?  (I didn't)

Yes, I do.

* are you using a .env file? (I didn't)

Yes, I do.

Note that to stop the debugging session I could not hit Ctrl-C in the terminal. Instead I had to use the VS Code stop button. However, I don't think that matters.

Yeah, I usually use the stop button too. But in my case I also has to close the Python Debug Console terminal else it will not be run the next time.

Also, I did notice that your launch.json is slightly different from the default, which looks like this:

Yours has a "--port=5002" arg, as well as a "console": "integratedTerminal" setting. However, I didn't have any trouble using your launch.json, so I don't think that is related.

Yes, I'm running the project on the specific port (as usually have several Flask projects to be tested and worked with). I added the console trying to fix this problem the it seemed to me I fixed it some day, but it broke again :( Thanks!

ericsnowcurrently commented 4 years ago

@int19h, @karthiknadig, any ideas on this?

saasforge commented 4 years ago

Maybe I should uninstall VS Code and all extensions and try to install them from scratch?

int19h commented 4 years ago

I don't think the missing or present env vars matter here. The difference is likely to do with whether this is the first command that is executed in that terminal, or a subsequent command. For the first command, VSCode sets the env vars when creating the terminal, and so it doesn't need to put them into the command line. When that terminal is reused for subsequent commands, it has to put the env vars in there. But they should be present either way - it can be tested by dumping os.environ from the script.

Another thing - this repro uses the stable debugger. I wonder if trying the experimental one would make any difference?

saasforge commented 4 years ago

I don't think the missing or present env vars matter here. The difference is likely to do with whether this is the first command that is executed in that terminal, or a subsequent command. For the first command, VSCode sets the env vars when creating the terminal, and so it doesn't need to put them into the command line. When that terminal is reused for subsequent commands, it has to put the env vars in there. But they should be present either way - it can be tested by dumping os.environ from the script.

Another thing - this repro uses the stable debugger. I wonder if trying the experimental one would make any difference?

Thanks for your response! When I was trying to install it I had the error, that says:

The install of '' was not successful for all the selected products.
Element "Identity" has invalid value for attribute 'version'.

The the log is here:

29/01/2020 4:43:46 PM - Microsoft VSIX Installer
29/01/2020 4:43:46 PM - -------------------------------------------
29/01/2020 4:43:46 PM - vsixinstaller.exe version:
29/01/2020 4:43:46 PM - 16.0.2264
29/01/2020 4:43:46 PM - -------------------------------------------
29/01/2020 4:43:46 PM - Command line parameters:
29/01/2020 4:43:46 PM - C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\VSIXInstaller.exe,C:\temp\ms-python-insiders.vsix
29/01/2020 4:43:46 PM - -------------------------------------------
29/01/2020 4:43:46 PM - Microsoft VSIX Installer
29/01/2020 4:43:46 PM - -------------------------------------------
29/01/2020 4:43:58 PM - Initializing Install...
29/01/2020 4:44:01 PM - Microsoft.VisualStudio.ExtensionManager.InvalidExtensionManifestException: Element 'Identity' has invalid value for attribute 'Version' ---> System.FormatException: Input string was not in a correct format.
   at System.Version.VersionResult.SetFailure(ParseFailureKind failure, String argument)
   at System.Version.TryParseComponent(String component, String componentName, VersionResult& result, Int32& parsedComponent)
   at System.Version.TryParseVersion(String version, VersionResult& result)
   at System.Version.Parse(String input)
   at System.Version..ctor(String version)
   at Microsoft.VisualStudio.ExtensionManager.ExtensionImpl.<>c.<ExtractManifestData>b__67_1(String s)
   at Microsoft.VisualStudio.ExtensionManager.ExtensionImpl.VerifyStringValue[T](String value, ErrorInfo info, Func`2 selector, Boolean isRequired, Int32 maxLength, T defaultValue)
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.ExtensionManager.ExtensionImpl.VerifyStringValue[T](String value, ErrorInfo info, Func`2 selector, Boolean isRequired, Int32 maxLength, T defaultValue)
   at Microsoft.VisualStudio.ExtensionManager.ExtensionImpl.ExtractManifestData(PackageManifest manifest)
   at Microsoft.VisualStudio.ExtensionManager.ExtensionImpl.ReadPackageManifest(XmlReader reader)
   at Microsoft.VisualStudio.ExtensionManager.ExtensionImpl.ReadManifest(Stream manifestStream)
   at Microsoft.VisualStudio.ExtensionManager.InstallableExtensionImpl.ReadVSIXManifestFromPackage(Stream stream, CultureInfo preferredCulture)
   at Microsoft.VisualStudio.ExtensionManager.InstallableExtensionImpl..ctor(String path, CultureInfo preferredCulture)
   at Microsoft.VisualStudio.ExtensionManager.ExtensionEngineImpl.CreateInstallableExtension(String extensionPath, CultureInfo preferredCulture)
   at Microsoft.VisualStudio.ExtensionManager.ExtensionEngineImpl.CreateInstallableExtension(String extensionPath)
   at VSIXInstaller.ExtensionService.GetInstallableData(String vsixPath, String extensionPackParentName, Boolean isRepairSupported, IStateData stateData, IEnumerable`1& skuData)
   at VSIXInstaller.ExtensionPackService.IsExtensionPack(IStateData stateData, Boolean isRepairSupported)
   at VSIXInstaller.ExtensionPackService.ExpandExtensionPackToInstall(IStateData stateData, Boolean isRepairSupported)
   at VSIXInstaller.App.Initialize(Boolean isRepairSupported)
   at VSIXInstaller.App.Initialize()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

The VS Code was closed at the moment.

ericsnowcurrently commented 4 years ago

@int19h, what's the best way to try out the "experimental" debugger?

int19h commented 4 years ago

https://github.com/microsoft/ptvsd/issues/1706#issuecomment-572287267

ericsnowcurrently commented 4 years ago

@saasforge, can you give that a try and let us know the outcome? Thanks!

saasforge commented 4 years ago

Unfortunately, the same error. Btw, recently I had to work with my older project and VS Code was working hellish well. What should I look at to figure out what's the difference between those projects (I still torture with a bad one :( )??!!

saasforge commented 4 years ago

Ok, I uninstalled VS Code, node.js, Python extension, then installed everything again, still no result. Everything even is getting worse - all my "good" projects became "bad" and I have to close the terminal now with ALL my projects :cry: :cry: :cry:

saasforge commented 4 years ago

What I found today was the "good" project has more commands in Output window -> dropdown. The "bad" project has only 2:

And the good one has also:

I don't know if it matters regarding this problem but at least there are some differences. Can you please check? Thanks!

ericsnowcurrently commented 4 years ago

@int19h, any other thoughts on this?

int19h commented 4 years ago

@saasforge My apologies, I didn't see your earlier comment about the error when installing VSIX. It looks like you double-clicked it to open? If you have the regular Visual Studio (not VSCode) installed, it registers itself to open .vsix, and tries to install them as VS extensions - this is what happened here. To make sure that it installs as a VSCode extension, you need to use "Extensions: Install from VSIX" command in the command palette (Ctrl+Shift+P).

saasforge commented 4 years ago

@int19h Pavel, thanks for your help. Unfortunately, it didn't help. The extension was installed successfully but it exposed the same behaviour. I believe the problem is not with VS code or extensions themselves but with my project. I can't figure out what is that. I have some idea, though, and would like to prove it :) will let you know how it'd go.

ericsnowcurrently commented 4 years ago

Thanks for the update, @saasforge. Please do let us know how it goes. :smile:

brettcannon commented 4 years ago

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.

saasforge commented 4 years ago

Ok, let me recap... I tried different settings for different project and nothing worked. Until some day it suddenly started working. Don't ask me why and how! I don't know. Anyway, the problem has gone... for now :)