Module

_reload

File watcher for development mode (--reload).

Polls the application's source directory for changes and signals the supervisor to restart workers when modifications are detected.

Uses stdlibpathlib + polling. Ignores __pycache__, .git, node_modules, and common virtual environment directories.

Functions

_should_watch 2 bool
Check if a path should be watched for changes.
def _should_watch(path: Path, extensions: frozenset[str] = _WATCH_EXTENSIONS) -> bool
Parameters
Name Type Description
path Path
extensions frozenset[str] Default:_WATCH_EXTENSIONS
Returns
bool
_snapshot 2 dict[str, float]
Take a snapshot of file modification times.
def _snapshot(directories: list[Path], extensions: frozenset[str] = _WATCH_EXTENSIONS) -> dict[str, float]
Parameters
Name Type Description
directories list[Path]
extensions frozenset[str] Default:_WATCH_EXTENSIONS
Returns
dict[str, float]
detect_changes 3 tuple[set[str], dict[str…
Compare current state against a previous snapshot.
def detect_changes(directories: list[Path], previous: dict[str, float], extensions: frozenset[str] = _WATCH_EXTENSIONS) -> tuple[set[str], dict[str, float]]
Parameters
Name Type Description
directories list[Path]

Directories to scan.

previous dict[str, float]

Previous snapshot from_snapshot().

extensions frozenset[str]

File extensions to watch.

Default:_WATCH_EXTENSIONS
Returns
tuple[set[str], dict[str, float]]
watch_for_changes 5 None
Poll directories for changes and call callback on detection. This is a blockin…
def watch_for_changes(directories: list[Path], callback: Callable[[], None], *, interval: float = 1.0, stop_event: threading.Event | None = None, extra_extensions: tuple[str, ...] = ()) -> None

Poll directories for changes and call callback on detection.

This is a blocking function designed to run in a thread. It polls at the given interval and callscallback()whenever changes are detected.

Parameters
Name Type Description
directories list[Path]

Directories to watch.

callback Callable[[], None]

Called (with no args) when changes are detected.

interval float

Polling interval in seconds (default: 1.0).

Default:1.0
stop_event threading.Event | None

Optional threading.Event to stop the watcher.

Default:None
extra_extensions tuple[str, ...]

Additional file extensions to watch beyond the built-in set (e.g.(".html", ".css", ".md")).

Default:()