Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watchdog: Prevent reload if a file gets closed without any changes #2945

Closed
lociii opened this issue Sep 5, 2024 · 7 comments · Fixed by #2947
Closed

watchdog: Prevent reload if a file gets closed without any changes #2945

lociii opened this issue Sep 5, 2024 · 7 comments · Fixed by #2947
Milestone

Comments

@lociii
Copy link
Contributor

lociii commented Sep 5, 2024

What's the issue?

watchdog 5.0 introduced a new signal that is fired when a file gets closed without any changes written.
This leads to random reloads when something opens and closes a file. opened events are already ignored, so we should ignore the new closed_no_write events too.

How to reproduce?

Update to watchdog 5.0+ and wait for the reloads to come in.

What's the expected behavior?

Werkzeug should only reload if there are actual changes to the code base.

Environment

  • Python version: 3.11.2
  • Werkzeug version: 3.0.4
  • watchdog version: 5.0.2
@marianobianchi
Copy link

I'm using Django and django-extensions. I started getting reloads on every request. After doing some checks I was able to find that it started happening after upgrading werkzeug from 3.0.3 to 3.0.4

@ckarli
Copy link

ckarli commented Sep 17, 2024

I'm using Django and django-extensions. I started getting reloads on every request. After doing some checks I was able to find that it started happening after upgrading werkzeug from 3.0.3 to 3.0.4

I am also having the same problem

I am using
werkzeug==3.0.4
watchdog==5.0.2

After a request i get bogus changes detected

backend-1 | * Detected change in '/backend/common/schema.py', reloading backend-1 | * Detected change in '/usr/local/lib/python3.12/site-packages/drf_spectacular/openapi.py', reloading backend-1 | * Detected change in '/usr/local/lib/python3.12/site-packages/drf_spectacular/utils.py', reloading backend-1 | * Detected change in '/usr/local/lib/python3.12/site-packages/drf_spectacular/generators.py', reloading backend-1 | * Detected change in '/usr/local/lib/python3.12/site-packages/drf_spectacular/views.py', reloading backend-1 | * Detected change in '/usr/local/lib/python3.12/site-packages/rest_framework/views.py', reloading backend-1 | * Detected change in '/usr/local/lib/python3.12/site-packages/django/views/generic/base.py', reloading backend-1 | * Detected change in '/usr/local/lib/python3.12/site-packages/django/views/decorators/csrf.py', reloading backend-1 | * Detected change in '/backend/common/authentication.py', reloading postgres-1 | 2024-09-17 08:08:21.866 UTC [104] LOG: could not receive data from client: Connection reset by peer backend-1 | * Restarting with watchdog (inotify)

@jdimmerman
Copy link
Contributor

Opened a PR but needs feedback on direction: #2954 (comment)

@lociii
Copy link
Contributor Author

lociii commented Oct 7, 2024

Opened a PR but needs feedback on direction: #2954 (comment)

I already opened one over a month ago. Not much progress from the maintainer side so far.
#2947

@jdimmerman
Copy link
Contributor

Thanks @lociii - much better solution. Closing mine

@lociii
Copy link
Contributor Author

lociii commented Oct 15, 2024

@ThiefMaster @davidism
This issue breaks runserver_plus from django-extensions for everyone not pinning watchdog to 4.x and using the file system events reload mechanism.
It would be really appreciated if my simple fix could be merged and released.

@mlgarchery
Copy link

mlgarchery commented Oct 15, 2024

Thank you very much @lociii for reporting the issue :)
I enforced watchdog version to be <5 in my project (using functions-framework) to fix it temporarily and move forward

@davidism davidism added this to the 3.0.5 milestone Oct 24, 2024
browniebroke added a commit to cookiecutter/cookiecutter-django that referenced this issue Oct 25, 2024
The issue that lead to this pinning should be fixed now: pallets/werkzeug#2945
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
6 participants