Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pyinotify
07-08-2017, 10:55 AM (This post was last modified: 07-19-2017 04:27 PM by rayluk.)
Post: #1
pyinotify
inotify (inode notify) is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes to applications.
pyinotify is a python wrapper for inotify. pyinotifiy has implemented recursive directory monitoring so it would be more easy to be used.

Can be install on Centos by
Code:
#pip install pyinotify
or
#yum install python-inotify

Can be used in python by
Code:
import pyinotify

Variables for inotify
1) max_queued_events
upper limit on the number of events that can be queued to the corresponding inotify instance. Events in excess of this limit are dropped, but an IN_Q_OVERFLOW event is always generated
2) max_user_instances
Upper limit of inotify instances can be created per real user ID.
3) max_user_watches
Upper limit on the number of watches that can be created per real user ID. ( upper limit of directories being watched )

Code:
Variables can be shown by
#sysctl fs.inotify.{name of variable}

Variables can be set by
#sudo sysctl fs.inotify.{name of variable}={value}

It is recommended to set max_user_watches and max_queued_events to a high value when the files being watched is a large amount to avoid errors.

Events
For general usages, it is recommended to use following mask.
"IN_CREATE", "IN_CLOSE_WRITE" , "IN_DELETE" , "IN_DONT_FOLLOW" , "IN_MODIFY" , "IN_MOVE_FROM" , "IN_MOVE_TO" , "IN_MOVE_SELF"

Recommend to ignore following events "IN_IGNORED", "IN_MOVE_SELF" as they are always duplicated with other events during a run.

Known Bug
Cannot update path of a directory when it is being moved from a watched directory to a unwatched directory.
pyinotify is not working on a mounted sshfs

Ref: https://github.com/seb-m/pyinotify
Find all posts by this user
Quote this message in a reply
07-19-2017, 04:23 PM (This post was last modified: 07-19-2017 04:26 PM by rayluk.)
Post: #2
RE: pyinotify
pyinotify is not working on a mounted sshfs
Example:
1) Host A installed pyinotify
2) Host B mount a drive from Host B by sshfs. (like running "sshfs HostB:~/drive /mnt/drive" on Host B
3) Host B runs pyinotify to monitor /mnt/drive.
4) Host A put data into ~/drive. There will be no event generated for the pyinotify in Host B
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: