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

Class ThreadedNotifier

source code


This notifier inherits from threading.Thread for instanciating a separate thread, and also inherits from Notifier, because it is a threaded notifier.

Note that every functionality provided by this class is also provided through Notifier class. Moreover Notifier should be considered first because it is not threaded and could be easily daemonized.

Instance Methods [hide private]
 
__init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None)
Initialization, initialize base classes.
source code
 
stop(self)
Stop notifier's loop.
source code
 
loop(self)
Thread's main loop.
source code
 
run(self)
Start thread's loop: read and process events until the method stop() is called.
source code

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, is_alive, join, setDaemon, setName, start

Inherited from threading.Thread (private): _reset_internal_locks, _set_daemon, _set_ident

Inherited from threading._Verbose (private): _note

Inherited from Notifier: append_event, check_events, coalesce_events, proc_fun, process_events, read_events

Inherited from Notifier (private): _sleep

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

Properties [hide private]

Inherited from threading.Thread: daemon, ident, name

Inherited from threading.Thread (private): _block

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, initialize base classes. 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. See base class.
  • 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.
  • 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 set 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 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#select.poll.poll
Overrides: object.__init__

stop(self)

source code 

Stop notifier's loop. Stop notification. Join the thread.

Overrides: Notifier.stop

loop(self)

source code 

Thread's main loop. Don't meant to be called by user directly. Call inherited start() method instead.

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

Parameters:
  • callback - 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 - This thread is daemonized if set to True.
  • args - 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.
Overrides: Notifier.loop

run(self)

source code 

Start thread's loop: read and process events until the method stop() is called. Never call this method directly, instead call the start() method inherited from threading.Thread, which then will call run() in its turn.

Overrides: threading.Thread.run