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

Make rebuild/reload act only when file is modified. #3677

Merged
merged 1 commit into from
Apr 8, 2023

Conversation

gipi
Copy link
Contributor

@gipi gipi commented Apr 2, 2023

Improve the event handler using directly the watchdog library's own handlers and trigger the actions only when a file is modified.

Should fix #3638

Pull Request Checklist

  • I’ve read the guidelines for contributing.
  • I updated AUTHORS.txt and CHANGES.txt (if the change is non-trivial) and documentation (if applicable).
  • I tested my changes.

Description

The original implementation triggered rebuild and reload on each possible filesystem event that is time consuming and can cause infinite loops, it's probably better to limit the rebuilding on file modification.

@gipi
Copy link
Contributor Author

gipi commented Apr 2, 2023

I'll complete all the steps in the checklist once I'm sure the change is ok, maybe I could add some tests.

@Kwpolska
Copy link
Member

Kwpolska commented Apr 2, 2023

I was able to reproduce this issue, but only with the latest version of watchdog. The issue seems to be caused by file open and close events (which weren’t raised before, and in fact, there is no separate method for file open events).

The on_modified event is not enough for us, as we also want to trigger rebuilds when files are created or deleted. I think we should keep the on_any_event handler, but filter out the opened/closed events. I think a better change would be to keep overriding dispatch, but instead filter the event types:

def dispatch(self, event):
    """Dispatch events to handler."""
    if event.event_type in {"opened", "closed"}:
        return
    self.loop.call_soon_threadsafe(asyncio.ensure_future, self.function(event))

Can you check if this fixes things for you as well? If yes, please change your pull request to the above.

@gipi gipi force-pushed the fix-event-handler branch 2 times, most recently from 1de30ca to bbd1c1b Compare April 8, 2023 10:22
@gipi
Copy link
Contributor Author

gipi commented Apr 8, 2023

I changed the patch as indicated and it seems to fix my issue.

@gipi
Copy link
Contributor Author

gipi commented Apr 8, 2023

Probably on_any_event() should be removed then.

@Kwpolska Kwpolska merged commit 2b01fa1 into getnikola:master Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nikola auto loops infinitely
2 participants