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 detects changes half a second later than dsoprea/PyInotify under Linux #390

Closed
Larivact opened this issue Dec 18, 2016 · 5 comments

Comments

@Larivact
Copy link

I am working on a project where the file changes should be detected as soon as possible.
I started out using watchdog since it's crossplatform and conveniently abstracts the filesystem events,
but I noticed that watchdog takes 0.5s longer than dsoprea/PyInotify to detect file changes. Is this just the price you have to pay for the abstraction? Or could watchdog be more optimized?

Code I used for benchmarking:

import time
import watchdog.events
import watchdog.observers

class EventHandler(watchdog.events.FileSystemEventHandler):
	def on_any_event(self, event):
		print(time.time())

observer = watchdog.observers.Observer()
observer.schedule(EventHandler(), '.', recursive=True)
observer.start()
input()
import time
import inotify.adapters

i = inotify.adapters.InotifyTree(b'.')

for event in i.event_gen():
	if event and 'IN_CLOSE_WRITE' in event[1]:
		print(time.time())
@DonyorM
Copy link
Contributor

DonyorM commented Dec 19, 2016

This has to do with how watchdog creates move events. In order to match inotify's move_from and move_to events to become a single move event as offered by watchdog, there needs to be a buffer time to find the matching event. This is set to 0.5 seconds I believe.

@Larivact
Copy link
Author

Buffering all events when only moved_from needs to be matched with moved_to seems to be inefficient. Wouldn't it be better to only wait 0.5s when moved_from occurs?

I don't get why my testing resulted in a 0.5s delay the timeouts all seem to be set to 1s.
Anyway is there a way to disable the buffering if you don't need the move events to be merged?

@DonyorM
Copy link
Contributor

DonyorM commented Dec 20, 2016

The delay is found in the inotify_buffer module with the delay variable being set to 0.5 on line 30. Right now there doesn't seem to be a way to disable it. However, you could just edit the code and set the delay variable to 0.

@Larivact
Copy link
Author

@DonyorM thanks. I monkey patched it using

watchdog.observers.inotify_buffer.InotifyBuffer.delay = 0

While this got rid of the delay the move events interestingly still seem to get merged.

@BoboTiG
Copy link
Collaborator

BoboTiG commented Jan 12, 2019

Closed with 2b2091a.

@BoboTiG BoboTiG closed this as completed Jan 12, 2019
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

No branches or pull requests

3 participants