From 426cbc6190560b3f7fb263499ec3891a3280e2a2 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Mon, 9 Mar 2026 14:42:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(test):=20=E5=9C=A8=20FileWatcher=20?= =?UTF-8?q?=E4=B8=AD=E6=B7=BB=E5=8A=A0=20force=5Fpolling=20=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=BB=A5=E5=A2=9E=E5=BC=BA=E6=96=87=E4=BB=B6=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytests/config_test/test_file_watcher.py | 2 +- src/config/file_watcher.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pytests/config_test/test_file_watcher.py b/pytests/config_test/test_file_watcher.py index a6b86477..319a17b0 100644 --- a/pytests/config_test/test_file_watcher.py +++ b/pytests/config_test/test_file_watcher.py @@ -123,7 +123,7 @@ async def test_add_callback_while_watcher_running(tmp_path: Path): dirs.mkdir(exist_ok=True) file = (dirs / "a.toml").resolve() file.touch() - watcher = FileWatcher(paths=[dirs], debounce_ms=200) + watcher = FileWatcher(paths=[dirs], debounce_ms=200, force_polling=True) calls = 0 diff --git a/src/config/file_watcher.py b/src/config/file_watcher.py index 0ec81e4a..eadabb96 100644 --- a/src/config/file_watcher.py +++ b/src/config/file_watcher.py @@ -55,9 +55,11 @@ class FileWatcher: callback_timeout_s: float = 10.0, callback_failure_threshold: int = 3, callback_cooldown_s: float = 30.0, + force_polling: bool = False, ) -> None: self._paths = [path.resolve() for path in paths] self._debounce_ms = debounce_ms + self._force_polling = force_polling self._callback_timeout_s = callback_timeout_s self._callback_failure_threshold = callback_failure_threshold self._callback_cooldown_s = callback_cooldown_s @@ -136,7 +138,7 @@ class FileWatcher: async def _run(self) -> None: while self._running: try: - async for changes in awatch(*self._paths, debounce=self._debounce_ms): + async for changes in awatch(*self._paths, debounce=self._debounce_ms, force_polling=self._force_polling): if not self._running: break normalized_changes = self._normalize_changes(changes)