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.

Flask does not reload modified code when running under WSL

See original GitHub issue

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?

Environment

  • Python version: 3.8.2 64-bit (from Ubuntu on WSL)
  • Flask version: 1.1.2
  • Werkzeug version: 1.0.1

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
haimatcommented, Jun 26, 2020

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.

That solved my issue, after uninstalling watchdog auto-reloading worked now, thanks!

0reactions
ThiefMastercommented, Jun 26, 2020

nevermind, i somehow thought this option existed but apparently there’s only --reload/--no-reload

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flask does not reload modified code when running under WSL
I am developing a Flask app on a Linux machine, which does correctly reload itself when I modify a Python source code file...
Read more >
Remote Development Tips and Tricks - Visual Studio Code
Visual Studio Code Remote Development troubleshooting tips and tricks for SSH, Containers, and the Windows Subsystem for Linux (WSL)
Read more >
Flask by Example – Implementing a Redis Task Queue
This part of the tutorial details how to implement a Redis task queue to handle text processing.
Read more >
PyCharm - Run/Debug Configuration: Flask Server - JetBrains
Run External tool: select to run an external application. In the dialog that opens, select one or multiple applications you want to run....
Read more >
TODO List Flask App in 30 minutes - Ti-Chung Cheng
We will complete a Todo demo App in this tutorial. The todo demo app can Create, Read, Update, Delete, tasks on this to-do...
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