关于实现 pyinotify 实例来监控目录的问题
我有一些关于 pyinotify 的基本问题,我似乎无法在其他地方找到答案。
1)对于连续目录监视器(和事件处理器),是否需要有一个 while( True ) 循环,或者连续事件“循环”是否由通知手表处理并在我移除手表时结束?
2) 如果 inotify 实例“打开”时文件已存在,会发生什么情况?最初我只想监视 IN_CREATE 但这不会处理预先存在的文件。
3) 与 #2 类似,如果我在事件处理器函数中创建文件,会发生什么情况? pyinotify 会将其缓存在其队列中并在“循环”再次开始时处理它,还是我会丢失此事件?
I have some basic questions about pyinotify that I can't seem to find the answers to elsewhere.
1) For a continuous directory monitor (and event processor) is it necessary to have a while( True ) loop or is the continuous event 'loop' handled by the notify watch and ended when I remove the watch?
2) What happens if files are pre-existing when the inotify instance is 'turned-on'? Initially I just want to monitor for IN_CREATE but this won't handle pre-existing files.
3) Similar to #2, what happens if a file gets created while I'm in my event processor function? Will pyinotify cache it in its queue and process it when the 'loop' starts again, or will I lose this event?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个
while-loop
,但它可以通过调用notifier.loop 隐式设置
方法:如果您想自己设置
while-loop
,您可以从这个 源代码 来自notifier.loop< /code>:
要删除特定文件或目录的监视,请调用
wm.rm_watch
。如果 inotify 实例“打开”时文件已存在,会发生什么情况?
在调用
wm.add_watch
之前不会生成任何事件。如果在我使用事件处理器函数时创建文件会发生什么?
事件在指定大小的缓冲区中排队
/proc/sys/fs/inotify/max_queued_events
。例如,在我的系统上这个数字是
如果文件系统生成足够的事件来填充缓冲区,同时
您正在处理先前的事件,然后您会收到
IN_Q_OVERFLOW
事件。
请参阅blucz 的回答中的评论。
You'll need a
while-loop
, but it can be set up implicitly by calling thenotifier.loop
method:If you wish to set up the
while-loop
yourself, you might start with this source code fromnotifier.loop
:To remove a watch of a particular file or directory, call
wm.rm_watch
.What happens if files are pre-existing when the inotify instance is 'turned-on'?
No event is generated before
wm.add_watch
is called.what happens if a file gets created while I'm in my event processor function?
The events are queued in a buffer of size
/proc/sys/fs/inotify/max_queued_events
. For example, on my systemthat number is
If the filesystem generates enough events to fill up the buffer while
you are processing a prior event, then you get a
IN_Q_OVERFLOW
event.
See the comment in blucz's answer.