使用 python select.kqueue() 检查文件是否被修改、删除或扩展
您好,我很难理解如何使用仅限 BSD 的 python 模块类 select.kqueue 和 select.kevent 来设置文件写入事件的监视。
我希望 python 程序能够在另一个进程写入文本文件时做出响应。 我的测试代码如下:
import os
myfd = os.open("/Users/hari/c2cbio/t.txt",os.O_RDONLY)
my_event=select.kevent(myfd,filter=select.KQ_FILTER_VNODE,fflags=select.KQ_NOTE_WRITE|select.KQ_NOTE_EXTEND)
# I now create a kqueue object and a control object
kq = select.kqueue()
# I dont know how to set the max_events if it is non zero the REPL does not return
kq.control([my_event],0,None)
我不知道如何继续检查这些事件是否确实发生。有人可以向我指出使用 kqueue 检测文件修改或任何其他事件(如文件删除、文件重命名等)的示例吗
Hi I am having a hard time understanding how to use the BSD only python module classes select.kqueue and select.kevent to setup a watch for file write events.
I want to a python program to respond whenever a text file is written to by another process.
My test code goes as follows:
import os
myfd = os.open("/Users/hari/c2cbio/t.txt",os.O_RDONLY)
my_event=select.kevent(myfd,filter=select.KQ_FILTER_VNODE,fflags=select.KQ_NOTE_WRITE|select.KQ_NOTE_EXTEND)
# I now create a kqueue object and a control object
kq = select.kqueue()
# I dont know how to set the max_events if it is non zero the REPL does not return
kq.control([my_event],0,None)
I dont know How to proceed to check that these events have indeed happened. Can someone point me to an example of using kqueue to detect file modification or any other events ( like file delete , file rename etc)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看看门狗模块的代码,我想出了这个。我不知道flag是否有必要。
Looking at the code for the watchdog module I came up with this . I dont know if the flags are necessary.