watchdog.observers.polling#

module:

watchdog.observers.polling

synopsis:

Polling emitter implementation.

author:

yesudeep@google.com (Yesudeep Mangalapilly)

author:

Mickaël Schoentgen <contact@tiger-222.fr>

Classes#

class watchdog.observers.polling.PollingEmitter(event_queue: EventQueue, watch: ObservedWatch, *, timeout: Seconds = 1.0, event_filter: list[type[FileSystemEvent]] | None = None, stat: Callable[[str], os.stat_result] = <built-in function stat>, listdir: Callable[[str | None], Iterator[os.DirEntry]] = <built-in function scandir>)[source]#

Bases: EventEmitter

Platform-independent emitter that polls a directory to detect file system changes.

on_thread_start() → None[source]#

Take the first snapshot of the watched directory.

Later snapshots are compared against this one to detect changes.

queue_events(timeout: Seconds) → None[source]#

Wait timeout seconds, then queue events for any changes.

Takes a new snapshot of the watched directory and compares it with the previous one. An event is queued for each file or directory that was created, deleted, modified or moved. Returns early if the emitter is stopped while waiting.

If the watched directory no longer exists or is not a directory, a DirDeletedEvent is queued and the emitter stops. Other OSError exceptions are logged and retried on the next poll.

Parameters:

timeout – Seconds to wait between successive snapshots. Polling emitters use this as the polling interval.

class watchdog.observers.polling.PollingObserver(*, timeout: Seconds = 1.0)[source]#

Bases: BaseObserver

Platform-independent observer that polls a directory to detect file system changes.

If a poll fails because the watched directory no longer exists (FileNotFoundError or NotADirectoryError), a DirDeletedEvent is emitted and watching stops. Any other OSError, for instance while a network share is briefly unreachable, is logged once and the next poll tries again. Changes made in the meantime are reported once the directory can be read again. An outage that the OS reports as ENOENT still looks like a deletion.

class watchdog.observers.polling.PollingObserverVFS(stat: Callable[[str], os.stat_result], listdir: Callable[[str | None], Iterator[os.DirEntry]], *, polling_interval: Seconds = 1)[source]#

Bases: BaseObserver

File system independent observer that polls a directory to detect changes.

__init__(stat: Callable[[str], os.stat_result], listdir: Callable[[str | None], Iterator[os.DirEntry]], *, polling_interval: Seconds = 1) → None[source]#
Parameters:
  • stat – stat function. See os.stat for details.

  • listdir – listdir function. See os.scandir for details.

  • polling_interval (Seconds) – interval between polling the file system.