为什么Watchdog会抛出此操作系统错误?

时间:2016-11-25 21:23:49

标签: python python-3.x daemon python-watchdog

我正在尝试编写一个守护进程来监视Python中的目录更改,我真的可以使用一些帮助。

到目前为止,我已经尝试了inotify和Watchdog。在他们的首页上运行示例代码时,这两个软件包都抛出了大量错误。谁能告诉我为什么我会收到这些错误?

以下是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()

这是我运行代码时的终端输出:

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

0 个答案:

没有答案