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)
Looking at the code for the watchdog module I came up with this . I dont know if the flags are necessary.