While working on a python project recently, I got to the point where I had to monitor a file for modifications. For example, I want to monitor an sqlite database (which is a normal file) to check if I’m the only one modifying it. Fortunately, pyinotify comes to the rescue! Unfortunately, the documentation on their website is a little outdated. Something important to be noted is that pyinotify is based on a Linux Kernel feature called inotify; this means that it’s only available under Linux.
Anyway, after several tries and failures I manage to come up with a decent implementation of a watcher class. The example I’m about to provide uses ThreadedNotifier, since my watcher is supposed to allow my GUI application to run in parallel. Also, please note that you can’t monitor the file itself, but instead you need to monitor the changes to files in a directory! This part was somehow omitted from the documentation; I wonder why.
read more
WebID Test Suite