spacepaste

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import select26 as select
import os

kq = select.kqueue()
fd = os.open("/tmp/a.txt", os.O_RDONLY)

ev = [select.kevent(fd, filter=select.KQ_FILTER_VNODE, flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE | select.KQ_EV_ONESHOT, 
                    fflags=select.KQ_NOTE_WRITE | select.KQ_NOTE_DELETE | select.KQ_NOTE_EXTEND)]
kq.control(ev, 0, 0)

try:
    while True:
        evts = kq.control([], 1, None)
        if len(evts):
            print evts
except KeyboardInterrupt:
    pass
else:
    kq.close()
    os.close(fd)