I have some basic questions about pyinotify that I can’t seem to find the answers to elsewhere.
1) For a continuous directory monitor (and event processor) is it necessary to have a while( True ) loop or is the continuous event ‘loop’ handled by the notify watch and ended when I remove the watch?
2) What happens if files are pre-existing when the inotify instance is ‘turned-on’? Initially I just want to monitor for IN_CREATE but this won’t handle pre-existing files.
3) Similar to #2, what happens if a file gets created while I’m in my event processor function? Will pyinotify cache it in its queue and process it when the ‘loop’ starts again, or will I lose this event?
You’ll need a
while-loop, but it can be set up implicitly by calling thenotifier.loopmethod:If you wish to set up the
while-loopyourself, you might start with this source code fromnotifier.loop:To remove a watch of a particular file or directory, call
wm.rm_watch.What happens if files are pre-existing when the inotify instance is ‘turned-on’?
No event is generated before
wm.add_watchis called.what happens if a file gets created while I’m in my event processor function?
The events are queued in a buffer of size
/proc/sys/fs/inotify/max_queued_events. For example, on my systemthat number is
If the filesystem generates enough events to fill up the buffer while
you are processing a prior event, then you get a
IN_Q_OVERFLOWevent.
See the comment in blucz’s answer.