4

I am trying to write a daemon to monitor directory changes in Python, and I really could use some help.

So far I have tried both inotify and Watchdog. Both packages have thrown massive errors when running their example code on their front pages. Can anyone tell me why I am getting these errors?

Here is the sample code from https://pypi.python.org/pypi/watchdog:

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')
    path = sys.argv[1] if len(sys.argv) > 1 else '.'
    event_handler = LoggingEventHandler()
    observer = Observer()
    observer.schedule(event_handler, path, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

Here is my terminal output when I run the code:

Traceback (most recent call last):
  File "test_wd.py", line 18, in <module>
    observer.start()
  File "/home/dhicks/anaconda3/lib/python3.5/site-packages/watchdog/observers/api.py", line 255, in start
    emitter.start()
  File "/home/dhicks/anaconda3/lib/python3.5/site-packages/watchdog/utils/__init__.py", line 111, in start
    self.on_thread_start()
  File "/home/dhicks/anaconda3/lib/python3.5/site-packages/watchdog/observers/inotify.py", line 121, in on_thread_start
    self._inotify = InotifyBuffer(path, self.watch.is_recursive)
  File "/home/dhicks/anaconda3/lib/python3.5/site-packages/watchdog/observers/inotify_buffer.py", line 35, in __init__
    self._inotify = Inotify(path, recursive)
  File "/home/dhicks/anaconda3/lib/python3.5/site-packages/watchdog/observers/inotify_c.py", line 187, in __init__
    self._add_dir_watch(path, recursive, event_mask)
  File "/home/dhicks/anaconda3/lib/python3.5/site-packages/watchdog/observers/inotify_c.py", line 364, in _add_dir_watch
    self._add_watch(path, mask)
  File "/home/dhicks/anaconda3/lib/python3.5/site-packages/watchdog/observers/inotify_c.py", line 385, in _add_watch
    Inotify._raise_error()
  File "/home/dhicks/anaconda3/lib/python3.5/site-packages/watchdog/observers/inotify_c.py", line 406, in _raise_error
    raise OSError(os.strerror(err))
OSError: Invalid argument
  • What OS are you using? – Reto Aebersold Nov 25 '16 at 21:36
  • And what file system are you watching? Anything special (e.g. Encrypted, OverlayFS) – Reto Aebersold Nov 25 '16 at 21:42
  • @RetoAebersold I am using Linux Mint, and no, nothing special. I just want to be able to monitor a directory passed as an argument. I already have a daemon that does this, but it's through polling. Which, as you probably know, does not scale well. Instead, it would be nice to have something more robust that could handle a directory as large as the root folder. – Dylan Hicks Nov 26 '16 at 15:01

0 Answers0