Question: How to view a file with changes using Python? suggests using watchdog, but I found that it could only see the directory, not the file, watchdog-test.py is a sample watchdog timer script:
$ python watchdog-test.py ab_test_res.sh & [1] 30628 fbt@fbt64 :~/laike9m$ Traceback (most recent call last): File "watchdog-test.py", line 15, in <module> observer.start() File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/api.py", line 255, in start emitter.start() File "/usr/local/lib/python2.7/dist-packages/watchdog/utils/__init__.py", line 111, in start self.on_thread_start() File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/inotify.py", line 121, in on_thread_start self._inotify = InotifyBuffer(path, self.watch.is_recursive) File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/inotify_buffer.py", line 35, in __init__ self._inotify = Inotify(path, recursive) File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/inotify_c.py", line 187, in __init__ self._add_dir_watch(path, recursive, event_mask) File "/usr/local/lib/python2.7/dist-packages/watchdog/observers/inotify_c.py", line 363, in _add_dir_watch raise OSError('Path is not a directory') OSError: Path is not a directory
So what is the best solution? I am using Linux (Ubuntu 12.04). BTW I do not want to use a poll.
source share