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

Added event filter for emitters #989

Merged
merged 1 commit into from May 14, 2023

Conversation

marioga
Copy link
Contributor

@marioga marioga commented May 10, 2023

In this PR, we add the capability of filtering which events are fired at the emitter level before inserting them to the event queue. In the case of inotify events, we optimize one step further and mask out events we are not interested in when we call inotify_add_watch. We tried to keep the API as general as possible and the changes are fully backwards compatible.

I noticed that there's an earlier draft PR that tried to achieve something similar here: https://github.com/gorakhargosh/watchdog/pull/911/files. It appears to be incomplete and largely abandoned though, so I figured I'll attempt my own thing.

The motivation for this work is that we observed a performance hit in some of our projects when upgrading to the latest watchdog. Events like file opening/closing can be very spammy, especially in a recursive setting. We successfully use the code in this PR to only fire events we care for in our project, e.g., file modifications.

@BoboTiG
Copy link
Collaborator

BoboTiG commented May 14, 2023

Thanks a lot @marioga, that's perfect!

@BoboTiG BoboTiG merged commit 48c49a1 into gorakhargosh:master May 14, 2023
41 of 45 checks passed
@Cartroo
Copy link

Cartroo commented May 17, 2023

I hoped to use this feature before realising it was so recently added, so I'm looking forward to this getting into a stable release. One observation is that there's a comment in inotify.py which implies that directory events will be implicitly added to the filter if running in recursive mode:

This emitter implementation therefore automatically adds watches for
sub-directories if running in recursive mode.

However, I can't see any evidence of that here, so unless I'm mistaken it looks like if someone sets an event filter without directory events then the recursive mode will be broken. Perhaps either this documentation should be amended, or the directory events implicitly added for the inotify case if running in recursive mode?

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.

None yet

3 participants