pywry.watcher¶
File watcher for hot reload support.
Data Types¶
pywry.watcher.WatchedFile
dataclass
¶
WatchedFile(path: Path, callback: Callable[[Path, str], None], label: str, last_triggered: float = 0.0)
Information about a watched file.
pywry.watcher.WindowDebouncer
dataclass
¶
Per-window debounce state.
File Watcher¶
pywry.watcher.FileWatcher
¶
Watch files for changes and trigger callbacks with debouncing.
Supports per-window debouncing so rapid saves across multiple files trigger a single callback per window.
Initialize the file watcher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
debounce_ms
|
int
|
Debounce time in milliseconds. Changes within this window will be batched into a single callback. |
100
|
Attributes¶
Functions¶
watch
¶
Watch a file for changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to the file to watch. |
required |
callback
|
Callable[[Path, str], None]
|
Function to call when file changes. Receives (path, label) as arguments. |
required |
label
|
str
|
Window label for grouping debounce. |
required |
unwatch
¶
Stop watching a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to stop watching. |
required |
label
|
str or None
|
If provided, only remove watches for this label. |
None
|
unwatch_label
¶
Stop watching all files for a window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Window label to unwatch. |
required |
Factory Functions¶
pywry.watcher.get_file_watcher
¶
get_file_watcher(debounce_ms: int = 100) -> FileWatcher
Get the global file watcher instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
debounce_ms
|
int
|
Debounce time for new watcher. |
100
|
Returns:
| Type | Description |
|---|---|
FileWatcher
|
Global FileWatcher instance. |
pywry.watcher.stop_file_watcher
¶
Stop the global file watcher if running.