A way to "listen" for changes to a file system from Python on Linux?
I want to be able to detect whenever new files are created or existing files are modified or deleted within a given directory tree (or set of trees). The brute force way to do this would be to just rescan the tree looking for changes, but I'm looking for a more "interrupt driven" solution where the file system tells my code what changed when it changes, rather than my code having to "poll" by continuously scanning through thousands开发者_StackOverflow中文版 of files looking for changes.
A way to do this in Python is preferred, but if I have to write a native module in C that's ok as a last resort.
pyinotify is IMHO the only way to get system changes without scanning the directory.
twisted.internet.inotify
! It's much more useful to have an event loop attached than just free-floating inotify. Using twisted also gives you filepath
for free, which is a nice library for more easily manipulating file paths in python.
精彩评论