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
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, force_kill=False, stdin=os.devnull, stdout=os.devnull, stderr=os.devnull)
pid_file: file to which the pid will be written.
source code
 
_sleep(self, ref_time) source code
 
loop(self, callback=None, daemonize=False, **args)
Events are read only once 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
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) seconds. But if timeout is None it can 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) - http://docs.python.org/lib/poll-objects.html#poll-objects

append_event(self, event)

source code 

Append a raw event to the event queue.

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

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.
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, force_kill=False, stdin=os.devnull, stdout=os.devnull, stderr=os.devnull)

source code 

pid_file: file to which the pid will be written. force_kill: if True kill the process associated to pid_file. stdin, stdout, stderr: files associated to common streams.

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

source code 

Events are read only once time every min(read_freq, timeout) seconds at best and only if the size to read is >= threshold.

Parameters:
  • callback (callable) - Functor called after each event processing. Expects to receive notifier object (self) as first parameter.
  • 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.

stop(self)

source code 

Close inotify's instance (close its file descriptor). It destroys all existing watches, pending events,...