Skip to content Skip to sidebar Skip to footer

Check If File Is Modified Deleted Or Extended Using Python Select.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 pr

Solution 1:

Looking at the code for the watchdog module I came up with this . I dont know if the flags are necessary.

#/usr/bin/env python
import select
import os

kq = select.kqueue()
# Use the OSX specific os.EVTONLY
# http://code.google.com/p/python-watchdog/source/browse/src/watchdog/observers/kqueue.py
fd = os.open("/Users/hari/c2cbio/t.txt", 0x8000)

ev = [select.kevent(fd, filter=select.KQ_FILTER_VNODE,flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE | select.KQ_EV_CLEAR,fflags=select.KQ_NOTE_WRITE | select.KQ_NOTE_EXTEND)]
#This call will block till the write or extend events occur
evts = kq.control(ev,1,None)
print "event occurred"

Post a Comment for "Check If File Is Modified Deleted Or Extended Using Python Select.kqueue()"