pyinotify:处理 IN_MODIFY 触发器

发布于 2024-09-10 16:32:18 字数 186 浏览 5 评论 0原文

我正在尝试查看目录,并正在寻找文件修改。考虑使用 pyinotify。问题是,在使用 IN_MODIFY 事件检查文件更改时,如果我通过网络将 12 MB 的小文件复制到目录,它会触发相当多的事件。

我不想处理这么多的触发器。我只想在复制文件后触发一个事件。我该如何实现这一目标?

任何 Pyinotify 专家都可以提供帮助

I am trying to watch a directory, and is looking for file modifications. Thinking of using pyinotify. Problem is that while using IN_MODIFY event to check for a file change, it triggers quite a number of events if I am copying even a small file of say 12 MB to the directory over a network.

I dont want to handle so many triggers. I want to only trigger a single event, after the file is copied. How do I achieve that?

Any Pyinotify gurus can help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

格子衫的從容 2024-09-17 16:32:18

尝试将 IN_MODIFY 更改为 IN_CLOSE_WRITE
当可写文件关闭时,会发生 IN_CLOSE_WRITE 事件。这种情况应该只发生一次,除非复制文件的程序选择多次关闭文件。

上述更改可能是您所需要的,但如果没有,这个基本代码
可以是一个非常有用的工具,可以查看事件何时发生。有了它,您应该能够确定要使用什么事件。


# 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()

Try changing IN_MODIFY to IN_CLOSE_WRITE.
An IN_CLOSE_WRITE event occurs when a writable file is closed. That should happen only once, unless the program that is copying the file chooses to close the file multiple times.

The above change is probably all you need, but if not, this basic code
can be a very useful tool for seeing what events occur when. With it, you should be able to determine what event to use.


# 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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文