我正在尝试监视一个目录,并且正在查找文件修改。考虑使用pyinotify。问题是,当使用IN_MODIFY事件检查文件更改时,如果我通过网络将例如12MB的小文件复制到目录,它会触发相当多的事件。
我不想处理这么多触发器。我只想在复制文件后触发一个事件。我该如何做到这一点?
任何Pyinotify专家都可以提供帮助
发布于 2010-07-16 01:52:39
尝试将IN_MODIFY更改为IN_CLOSE_WRITE。关闭可写文件时会发生IN_CLOSE_WRITE事件。这种情况应该只发生一次,除非复制文件的程序选择多次关闭该文件。
上面的更改可能就是您需要的全部,但如果不是这样,this basic code可能是一个非常有用的工具,用于查看何时发生了什么事件。有了它,您应该能够确定要使用的事件。
# Example: loops monitoring events forever.
#
import pyinotify
# Instanciate a new WatchManager (will be used to store watches).
wm = pyinotify.WatchManager()
# Associate this WatchManager with a Notifier (will be used to report and
# process events).
notifier = pyinotify.Notifier(wm)
# Add a new watch on /tmp for ALL_EVENTS.
wm.add_watch('/tmp', pyinotify.ALL_EVENTS)
# Loop forever and handle events.
notifier.loop()https://stackoverflow.com/questions/3258066
复制相似问题