I'm using Watchdog to monitor a network directory, non-recursive, for a specific pattern of files to be created over time. The issue I am seeing is that while it works fantastic when I test locally, if I make changes to the monitored directory from a remote machine, the events are not triggered.
Here are the specific details of my configuration:
An example of my problem can be easily reproduced by using the stock example snippet:
import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
event_handler = LoggingEventHandler()
observer = Observer()
observer.schedule(event_handler, path=sys.argv[1], recursive=False)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
If you start this on a network directory, and then make changes from the same system, the events are dispatched. But if you then make changes to the directory from another machine on the network, no events are dispatched.
Am I missing something regarding limitations of kqueue (or could be FSEvents on OSX, since it says its preferred first by Watchdog)?
I was stoked on this python package, and was going to start using it for other scripts to replace filesystem polling, but I can't seem to find any information regarding why I am seeing this issue.
Update
I also tested MacFSEvents and got the same problem. Then I modified the above test script to forcibly try different observers:
# does not work with remote changes
from watchdog.observers.fsevents import FSEventsObserver as Observer
# does not work with remote changes
from watchdog.observers.kqueue import KqueueObserver as Observer
# only option that works because its actually polling every second
from watchdog.observers.polling import PollingObserver as Observer
So at least for now, I can use the polling observer and not have to modify my code, until someone can shed some light on the real problem I am having.
I'm pretty sure filesystem events don't work over NFS - the reason being that the way the kernel manages file system events normally is that it has a layer in the kernel that triggers on activity - with NFS there's no facility for notifying of changes, you can only get a list of inodes, write some blocks, read some blocks.. etc. It's pretty minimal.
For filesystem events to work over NFS, you would have to be constantly polling the NFS server.
There may be some facility for this with AFP, which if you've got the juice you can just install netatalk and try that.
If you absolutely need to do something like this and netatalk doesn't do it - your best bet is to get OSXFuse up and running and write an NFS overlay that actually does just sit there and poll for changes. But, you'll be limited to 'truncated,modified,appended,deleted', etc.
See Also: Use libfuse in a project, without root access (for installation)? FTP mounts & inotify/kqueue/FSEvents
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With