Module pyinotify :: Class Notifier
[hide private]
[frames] | no frames]

Class Notifier

source code


Read notifications, process events.

Instance Methods [hide private]
 
__init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None)
Initialization.
source code
 
append_event(self, event)
Append a raw event to the event queue.
source code
 
proc_fun(self) source code
 
coalesce_events(self, coalesce=True)
Coalescing events.
source code
bool
check_events(self, timeout=None)
Check for new events available to read, blocks up to timeout milliseconds.
source code
 
read_events(self)
Read events from device, build _RawEvents, and enqueue them.
source code
 
process_events(self)
Routine for processing events from queue by calling their associated proccessing method (an instance of ProcessEvent).
source code
 
__daemonize(self, pid_file=None, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null') source code
 
_sleep(self, ref_time) source code
 
loop(self, callback=None, daemonize=False, **args)
Events are read only one time every min(read_freq, timeout) seconds at best and only if the size to read is >= threshold.
source code
 
stop(self)
Close inotify's instance (close its file descriptor).
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None)
(Constructor)

source code 

Initialization. read_freq, threshold and timeout parameters are used when looping.

Parameters:
  • watch_manager (WatchManager instance) - Watch Manager.
  • default_proc_fun (instance of ProcessEvent) - Default processing method. If None, a new instance of PrintAllEvents will be assigned.
  • read_freq (int) - if read_freq == 0, events are read asap, if read_freq is > 0, this thread sleeps max(0, read_freq - (timeout / 1000)) seconds. But if timeout is None it may be different because poll is blocking waiting for something to read.
  • threshold (int) - File descriptor will be read only if the accumulated size to read becomes >= threshold. If != 0, you likely want to use it in combination with an appropriate value for read_freq because without that you would keep looping without really reading anything and that until the amount of events to read is >= threshold. At least with read_freq set you might sleep.
  • timeout (int) - see read_freq above. If provided, it must be set in milliseconds. See https://docs.python.org/2/library/select.html#polling-objects
Overrides: object.__init__

append_event(self, event)

source code 

Append a raw event to the event queue.

Parameters:
  • event (_RawEvent instance.) - An event.

coalesce_events(self, coalesce=True)

source code 

Coalescing events. Events are usually processed by batchs, their size depend on various factors. Thus, before processing them, events received from inotify are aggregated in a fifo queue. If this coalescing option is enabled events are filtered based on their unicity, only unique events are enqueued, doublons are discarded. An event is unique when the combination of its fields (wd, mask, cookie, name) is unique among events of a same batch. After a batch of events is processed any events is accepted again. By default this option is disabled, you have to explictly call this function to turn it on.

Parameters:
  • coalesce (Bool) - Optional new coalescing value. True by default.

check_events(self, timeout=None)

source code 

Check for new events available to read, blocks up to timeout milliseconds.

Parameters:
  • timeout (int) - If specified it overrides the corresponding instance attribute _timeout. timeout must be sepcified in milliseconds.
Returns: bool
New events to read.

process_events(self)

source code 

Routine for processing events from queue by calling their associated proccessing method (an instance of ProcessEvent). It also does internal processings, to keep the system updated.

__daemonize(self, pid_file=None, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null')

source code 
Parameters:
  • pid_file - file where the pid will be written. If pid_file=None the pid is written to /var/run/<sys.argv[0]|pyinotify>.pid, if pid_file=False no pid_file is written.
  • stdin
  • stdout
  • stderr - files associated to common streams.

loop(self, callback=None, daemonize=False, **args)

source code 

Events are read only one time every min(read_freq, timeout) seconds at best and only if the size to read is >= threshold. After this method returns it must not be called again for the same instance.

Parameters:
  • callback (callable object or function) - Functor called after each event processing iteration. Expects to receive the notifier object (self) as first parameter. If this function returns True the loop is immediately terminated otherwise the loop method keeps looping.
  • daemonize (boolean) - This thread is daemonized if set to True.
  • args (various) - Optional and relevant only if daemonize is True. Remaining keyworded arguments are directly passed to daemonize see __daemonize() method. If pid_file=None or is set to a pathname the caller must ensure the file does not exist before this method is called otherwise an exception pyinotify.NotifierError will be raised. If pid_file=False it is still daemonized but the pid is not written in any file.

stop(self)

source code 

Close inotify's instance (close its file descriptor). It destroys all existing watches, pending events,... This method is automatically called at the end of loop(). Afterward it is invalid to access this instance.