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:
EventEmitterPlatform-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
timeoutseconds, 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
DirDeletedEventis queued and the emitter stops. OtherOSErrorexceptions 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:
BaseObserverPlatform-independent observer that polls a directory to detect file system changes.
If a poll fails because the watched directory no longer exists (
FileNotFoundErrororNotADirectoryError), aDirDeletedEventis emitted and watching stops. Any otherOSError, 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 asENOENTstill 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:
BaseObserverFile 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.statfor details.listdir – listdir function. See
os.scandirfor details.polling_interval (Seconds) – interval between polling the file system.