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