pallets / werkzeug

The comprehensive WSGI web application library.
https://werkzeug.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
6.65k stars 1.73k forks source link

Flask Watchdog (windowsapi) erroneously detects changes in site-package files that aren't changing #2490

Closed weevef closed 2 years ago

weevef commented 2 years ago

I'm running a development server using if __name__ == "__main__": app.run(host='0.0.0.0', threaded=True, port=5000, use_reloader=True, debug=True) and Flask autoreloads randomly* on file changes from site-packages and other module scripts. (*This can be recreated by manually opening any python file within site-packages)

There are two issues with this: 1) I assume that the watchdog is detecting file accessing as a "change" when it should instead trigger a reload when the file is changed 2) The watchdog shouldn't be watching .py files outside of the project directory

The reason this is a bit annoying is that by using VSCode or Spyder to work, these editors "touch" lots of .py files while in use, and the Flask server reloads for every time this occurs.

Using python app.py: python_app python_app_2

Using flask run --reload: flask_run_reload

Note that the only times the watchdog should've reloaded is on app.py changes. I've double checked with some of the site-packages files and their creation/last accessed/last written times do not line up with the times the watchdog chose to reload on said file.

Environment:

davidism commented 2 years ago

I can't reproduce this issue with the information provided. I cannot get the reloader to trigger on file access. If you think there's an issue with how Watchdog is detecting changes, report that to Watchdog.

Note that the only times the watchdog should've reloaded is on app.py changes.

That's not the case. The Werkzeug reloader will use Watchdog to watch changes in sys.path and imported modules. For example, if you install/upgrade a package while the reloader is running, it will reload.