I used Visual Studio 2017 as IDE for my small Flask project, but when I tried to upgrade to VS2019, it just won't start any more, the Python console stucked at
* Serving Flask app "flask_vs2019" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Restarting with stat
Then I created a new Flask project via VS2019 wizard, added debug=True and it stucked at restarting. The launch code are shown below:
import os
from flask_vs2019 import app
if __name__ == '__main__':
HOST = os.environ.get('SERVER_HOST', 'localhost')
try:
PORT = int(os.environ.get('SERVER_PORT', '5555'))
except ValueError:
PORT = 5555
app.run(HOST, PORT, debug=True)
I tried multiple workarounds and I'm pretty sure it is a VS 2019 issue. Flask works when:
- using VS 2017 with exact same code
- using a cmd console and launch by
flask runorpython -m flask run - switch off reloader with
use_reloader=FalseorDEBUG=False, which is unacceptable since you have to relaunch Flask whenever you change your code.
Flask won't work when:
- using VS 2019 (16.7) for any version of Flask and werkzeug
- set
FLASK_ENV=developmentand/orDEBUG=Trueas environment variable - installing watchdog package in virtual environment
In fact I found that the exact same issue was reported on Visual Studio Developer Community back on March 2020, but "this issue didn't have much product team activity and a very small amount of new votes or comments. Based on this, its severity, and affected area, it’s my experience that this issue is very unlikely to be fixed". Well I guess I will have to stick with VS 2017 for now.
Even if I turned off debug mode, the Python console still didn't work properly as the color output was broken.
127.0.0.1 - - [08/Aug/2020 13:59:02] "[37mGET / HTTP/1.1[0m" 200 -
127.0.0.1 - - [08/Aug/2020 13:59:02] "[37mGET /static/content/bootstrap.min.css HTTP/1.1[0m" 200 -
127.0.0.1 - - [08/Aug/2020 13:59:02] "[37mGET /static/content/site.css HTTP/1.1[0m" 200 -
127.0.0.1 - - [08/Aug/2020 13:59:03] "[33mGET /favicon.ico HTTP/1.1[0m" 404 -
Work around with colorama setup colorama.init(autoreset=True) won't work. In VS2017 no workaround would be needed and color output just works as is.