INotify

class kaa.inotify.INotify

Monitor files and directories, invoking callbacks when changes occur.

Multiple instances of this class can be created, but note that there is a per-user limit of the number of INotify instances allowed, which is controlled by /proc/sys/fs/inotify/max_user_instances

Synopsis

Class Hierarchy

kaa.Object
└─ kaa.inotify.INotify

Methods
get_watches()Returns a list of all paths monitored by the object.
has_watch()Determine if the given path is currently watched by the INotify object.
ignore()Removes a watch on the given path.
mask_to_string()Converts a bitmask of events to a human-readable string.
watch()Begin monitoring a file or directory for specific events.
Properties
This class has no properties.
Signals
eventEmitted when an event occurs on any file or directory currently being monitored by this INotify instance.

Methods

get_watches()

Returns a list of all paths monitored by the object.

Returns:list of strings
has_watch(path)

Determine if the given path is currently watched by the INotify object.

Parameters:path (str) – the path that had been previously passed to watch()
Returns:True if there is a matching monitor, or False otherwise.
ignore(path)

Removes a watch on the given path.

Parameters:path (str) – the path that had been previously passed to watch()
Returns:True if a matching monitor was removed, or False otherwise.
static mask_to_string(mask)

Converts a bitmask of events to a human-readable string.

Parameters:mask (int) – the bitmask of events
Returns:a string in the form EVENT1 | EVENT2 | EVENT3 ...
watch(path, mask=None)

Begin monitoring a file or directory for specific events.

Parameters:
  • path (str) – the full path to the file or directory to be monitored
  • mask (int) – a bitmask of events for which to notify, or None to use the default mask (see below).
Returns:

Signal object that is emitted when an event occurs on path.

The default mask is anything that causes a change (new file, deleted file, modified file, or attribute change on the file).

Callbacks connected to the returned signal are invoked with the same arguments as the event signal.

The total number of watches (across all INotify instances) is controlled by /proc/sys/fs/inotify/max_user_watches

Signals

event

Emitted when an event occurs on any file or directory currently being monitored by this INotify instance.

def callback(mask, filename, target)
Param mask:a bitmask of events
Type mask:int
Param source:the filename the event applies to
Type filename:str
Param target:if the mask contains both MOVED_TO | MOVED_FROM, filename was renamed to target. Otherwise, target is None.

Previous topic

Object Database

Next topic

Utility Functions

This Page