while True: # loop forever
try:
# process the queue of events as explained above notifier.process_events()
if notifier.check_events():
# read notified events and enqeue them notifier.read_events()
# you can do some tasks here...
except KeyboardInterrupt:
# destroy the inotify's instance on this interrupt (stop monitoring) notifier.stop()
break
========
To give this a more repeatable test, here is a python file which can be used to verify. When I do
(sudo bash)
mkdir src tgt
mount -t ecryptfs src tgt
(in window 1):
python inotify_test.py
(in window 2):
echo hi > hi
echo there >> hi
I see: natty-amd64: ~# python inotify_test.py
root@ecryptfs-
Create: /home/serge/src/hi
MOdified: /home/serge/src/hi
MOdified: /home/serge/src/hi
so the modified inotify events are sent, but the closed-write are not.
======= ======= ======= ====
import os
from pyinotify import WatchManager, Notifier, ThreadedNotifier, EventsCodes, ProcessEvent
wm = WatchManager()
mask = EventsCodes. ALL_FLAGS[ 'IN_DELETE' ] | EventsCodes. ALL_FLAGS[ 'IN_CREATE' ] | EventsCodes. ALL_FLAGS[ 'IN_MODIFY' ] | EventsCodes. ALL_FLAGS[ 'IN_CLOSE_ WRITE'] # watched events
class PTmp(ProcessEvent): IN_CREATE( self, event): join(event. path, event.name)
def process_
print "Create: %s" % os.path.
def process_ IN_DELETE( self, event): join(event. path, event.name)
print "Remove: %s" % os.path.
def process_ IN_MODIFY( self, event): join(event. path, event.name)
print "MOdified: %s" % os.path.
def process_ IN_CLOSE_ WRITE(self, event): join(event. path, event.name)
print "closed write: %s" % os.path.
notifier = Notifier(wm, PTmp())
wdd = wm.add_ watch(' /home/serge/ src/', mask, rec=True)
while True: # loop forever
notifier. process_ events( ) check_events( ):
notifier. read_events( )
notifier. stop()
try:
# process the queue of events as explained above
if notifier.
# read notified events and enqeue them
# you can do some tasks here...
except KeyboardInterrupt:
# destroy the inotify's instance on this interrupt (stop monitoring)
break
========