Repository navigation
API turboframe.watch
Source: turboframe/watch.py. Generated from the code of TurboFrame 0.3.0 by tools/wiki_api.py.
Folders watched for changes made outside the application, through the system's own notifications.
watchdog's native observer (inotify on Linux, FSEvents on macOS, ReadDirectoryChangesW on Windows) watches a set of folders, each one alone (not recursively): a project tree gives the folders it shows open. No folder is ever listed on a timer: nothing happens until the system says something changed.
An entry created, deleted, renamed or moved in a watched folder makes that folder affected; a move affects both folders, the one it left and the one it went to; on macOS, a watched folder reported as modified is affected itself (FSEvents may say only that; elsewhere it also comes for a file written in it). A file's contents changing is not a change of its folder. The caller compares what it shows with the folder before reading it again, so a spurious report (FSEvents may call a modified file created) costs one listing of that folder, not a refresh. Events are coalesced: the first starts a short wait (delay), those that arrive meanwhile join it, and then the affected folders are handed over once, without repeats, with the generation they belong to (a later set_folders or stop makes earlier ones stale). A storm (a checkout, a package install) is bounded: past max_pending folders the batch says everything watched instead of growing.
on_change and on_error run on watchdog's or the timer's threads: the caller moves them to its own thread (Textual: call_from_thread) and never touches widgets from them. Setting the same folders again changes nothing: batches already gathered for them stay current. A folder the system refuses to watch (a limit, permissions, a network filesystem) is reported once through on_error and left out; nothing polls instead.
watchdog is needed only once a folder is watched, and comes with the watch extra: pip install "turboframe[watch] @ git+...". Tests pass an observer_factory instead.
DELAY, MAX_WATCHED, MAX_PENDING, MODIFIED_FOLDERS, Batch, FolderWatcher
0.3
64
128
False
class Batch
Batch(generation: int, folders: frozenset[Path], everything: bool = False)Folders whose entries changed, for one generation of the watched set.
class FolderWatcher
FolderWatcher(on_change: Callable[[Batch], None], on_error: Callable[[Path, str], None] | None = None, *, delay: float = 0.3, max_watched: int = 64, max_pending: int = 128, observer_factory: Callable[[], object] | None = None)Watches folders one by one (not recursively) and reports which changed, coalesced.
-
set_folders(folders: Iterable[Path]) -> None: Watch exactly these folders (the firstmax_watched): new ones are added, gone ones dropped. -
is_current(batch: Batch) -> bool:batchbelongs to the folders watched now (not to a set changed or stopped since). -
stop() -> None: Every watch dropped, the pending batch forgotten, watchdog's threads ended.
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links