I am developing a Flask app on a Linux machine, which does correctly reload itself when I modify a Python source code file (when running in debug mode). Sometimes though I need to develop on a Windows machine, using WSL, but the very same Flask app sources. That basically works fine, however, under WSL the auto-reload feature does not seem to work any more. I can change the Python sources, but nothing happens - I need to manually shutdown and restart the Flask server.
Is this a known bug under WSL? Do I need to start the Flask application in a certain way?
As reference, here is how I start the application under VS Code:
"configurations": [
{
"name": "Run Server",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "run.py",
"FLASK_ENV": "development",
},
"args": [
"run"
],
}
]
... which starts the the Flask appliacation under WSL with these output:
* Serving Flask app "run.py" (lazy loading)
* Environment: development
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with inotify reloader
* Debugger is active!
* Debugger PIN: 182-804-918
That output looks fine to me, but still no auto-reload.
Any ideas?
It's probably due to inotify not working well under the WSL. Try uninstalling the watchdog package, as that will force Flask to use the default "stat" reloader, which should behave better.
You can also use --reloader stat for the same effect ;)
You can also use
--reloader statfor the same effect ;)
How do I start Flask with this option (in VS Code)?
I tried this:
mfb@Sector2:/data/Python/MLserver$ FLASK_APP="run.py" FLASK_ENV="development" flask run --reloader stat
Usage: flask run [OPTIONS]
Try "flask run --help" for help.
Error: no such option: --reloader
nevermind, i somehow thought this option existed but apparently there's only --reload/--no-reload...
It's probably due to inotify not working well under the WSL. Try uninstalling the
watchdogpackage, as that will force Flask to use the default "stat" reloader, which should behave better.
That solved my issue, after uninstalling watchdog auto-reloading worked now, thanks!
Most helpful comment
That solved my issue, after uninstalling
watchdogauto-reloading worked now, thanks!