Registry / devops / watchdog-gevent

watchdog-gevent

JSON →
library0.2.1pypypi✓ verified 22d ago

watchdog-gevent is a Python library that provides a gevent-based observer for the `watchdog` file system monitoring library. It allows `watchdog` to function efficiently within a gevent cooperative multitasking environment, replacing the default threading-based observer. The current version is 0.2.1, with recent updates in late 2024, indicating an active but low-cadence maintenance.

pip install watchdog-gevent
INSTALL
IMPORT
SIG · WATCHDOG-GEVENT
W
watchdog-gevent
devopspythonv0.2.1
Install
2.7s avg
Import
177ms
Disk
32MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 3.1s
py 3.11
✓ —
✓ 2.8s
py 3.12
✓ —
✓ 2.4s
py 3.13
✓ —
✓ 2.6s
py 3.9
✕ build_error
✕ build_error
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Observer
from watchdog_gevent import Observer
This is the gevent-specific observer class.
FileSystemEventHandler
from watchdog.events import FileSystemEventHandler
Standard event handler from the core watchdog library.
monkey.patch_all
import gevent.monkey; gevent.monkey.patch_all()
import gevent.monkey; # then import other modules
gevent.monkey.patch_all() must be called early in the application's lifecycle, before other modules that might use standard blocking I/O or threading functions are imported, for watchdog-gevent to work correctly.

This quickstart demonstrates how to use `watchdog-gevent` to monitor a directory. It's crucial to apply `gevent.monkey.patch_all()` at the very beginning of your script, before importing other modules that might rely on blocking I/O or threading, to ensure the gevent observer functions correctly within the cooperative multitasking environment. The example creates a temporary directory, sets up an observer, and prints messages for file creation, deletion, and modification events.

import time import os import gevent.monkey from watchdog.events import FileSystemEventHandler from watchdog_gevent import Observer # IMPORTANT: Apply gevent monkey patching BEFORE importing other blocking libraries gevent.monkey.patch_all() class MyHandler(FileSystemEventHandler): def on_created(self, event): print(f"Gevent: File created: {event.src_path}") def on_deleted(self, event): print(f"Gevent: File deleted: {event.src_path}") def on_modified(self, event): print(f"Gevent: File modified: {event.src_path}") # Note: watchdog-gevent does not emit on_moved events. # def on_moved(self, event): # print(f"Gevent: File moved from {event.src_path} to {event.dest_path}") if __name__ == "__main__": # Create a temporary directory for demonstration path = os.path.join(os.getcwd(), "gevent_test_dir") os.makedirs(path, exist_ok=True) print(f"Monitoring directory: {path}") event_handler = MyHandler() observer = Observer() observer.schedule(event_handler, path, recursive=True) observer.start() try: while True: time.sleep(1) # gevent.sleep(1) would also work after monkey-patching except KeyboardInterrupt: observer.stop() observer.join() print("Observer stopped.") # Clean up os.rmdir(path)
Debug
Known issues
breaking`watchdog-gevent` fundamentally relies on `gevent.monkey.patch_all()` being called at the very beginning of your application. Failure to do so, or patching too late, will result in the observer not functioning correctly or blocking the gevent event loop.
fix
Ensure `import gevent.monkey; gevent.monkey.patch_all()` is the first significant code executed in your application, before any other I/O or threading-related imports.
affects: <=0.2.1
gotchaThis library explicitly notes that it does not emit file and directory move (rename) events. If your application requires detecting these specific event types, `watchdog-gevent` will not provide them.
fix
Implement custom logic using `on_created` and `on_deleted` events to infer moves, or consider using the standard `watchdog` observers if `gevent` compatibility for move events is not a strict requirement.
affects: <=0.2.1
gotchaAs a gevent-based library, running CPU-intensive synchronous code within a greenlet can block the entire gevent event loop, leading to 'greenlet starvation' and unresponsiveness. This is a common pitfall in gevent applications.
fix
Offload CPU-bound tasks to separate processes or threads using `gevent.threadpool`, or ensure CPU-intensive operations are non-blocking. File I/O, even with monkey-patching, can be blocking on some operating systems; use `gevent.threadpool` for concurrent file I/O.
affects: All
compatibility`watchdog-gevent` itself states dependencies on `watchdog` (0.8+) and `gevent` (1.1+). However, recent versions of the underlying `watchdog` and `gevent` libraries (e.g., watchdog 3.0.0+, gevent 25.9.2.dev0+) officially support Python 3.9 and newer. Ensure your Python environment meets these transitive requirements.
fix
Use Python 3.9 or newer. Consult the documentation for `watchdog` and `gevent` for their current Python version requirements.
affects: All
Upgrade
Version history
0.2.1latest on PyPI · released Oct 19, 2024
Audit
Dependencies
watchdogrequiredCore file system monitoring library. Requires version 0.8+ for watchdog-gevent. Current watchdog versions (3.0.0+) require Python 3.9+.
geventrequiredAsynchronous I/O framework. Requires version 1.1+ for watchdog-gevent. Current gevent versions (25.9.2.dev0+) require Python 3.9+.
Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
watchdog-gevent — pip install watchdog-gevent · libregistry