Flask Auto Reload Is Not Detecting Changes in a VM

So I use Vagrant/virtual machines in my daily development and with that comes annoyances that my host-machine-only friends don’t experience.

I have my Flask app set up to detect changes and reload whenever static files change.

However, Werkzeug updated and my Flask’s auto reload stopped working.

Turns out it was using inotify and since I’m on a virtual machine, (using the /vagrant/ directory), inotify can’t detect changes on a mounted filesystem.

The solution was to use stat.

from flask import Flask
app = Flask(__name__)

def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run(extra_files=my_static_files, reloader_type='stat')

Of course, there’s some disadvantages to stat, it might technically be a watchdog issue, and Werkzeug technically updated a long time ago.

Anyhoo, here’s my quick and dirty solution. I’m posting it ’cause it was hard to search for.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: