Skip to content

Commit b0e52e8

Browse files
Change FileWatcher to stop printing watchfiles debug log
The underlying Rust code performs periodic checks to see if it should stop watching. These checks raise TimeoutError, which by default would log misleading debug messages. Setting yield_on_timeout=True makes it yield an empty set instead of printing debug logs. We handle these empty sets in the `ready()` method by continuing to wait.
1 parent b3c98e5 commit b0e52e8

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/frequenz/channels/file_watcher.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ def __init__(
159159
watch_filter=self._filter_events,
160160
force_polling=force_polling,
161161
poll_delay_ms=int(polling_interval.total_seconds() * 1_000),
162+
# The underlying Rust code performs periodic checks to see if it should stop watching.
163+
# These checks raise TimeoutError, which by default would log misleading debug messages.
164+
# Setting yield_on_timeout=True makes it yield an empty set instead of printing debug
165+
# logs. We handle these empty sets in the `ready()` method by continuing to wait.
166+
yield_on_timeout=True,
162167
)
163168
self._awatch_stopped_exc: Exception | None = None
164169
self._changes: set[FileChange] = set()
@@ -204,11 +209,13 @@ async def ready(self) -> bool:
204209
if self._awatch_stopped_exc is not None:
205210
return False
206211

207-
try:
208-
self._changes = await anext(self._awatch)
209-
except StopAsyncIteration as err:
210-
self._awatch_stopped_exc = err
211-
return False
212+
# awatch will yield an empty set if rust notify timeout is reached.
213+
while len(self._changes) == 0:
214+
try:
215+
self._changes = await anext(self._awatch)
216+
except StopAsyncIteration as err:
217+
self._awatch_stopped_exc = err
218+
return False
212219

213220
return True
214221

tests/test_file_watcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ async def test_file_watcher_filter_events(
102102
watch_filter=filter_events,
103103
force_polling=True,
104104
poll_delay_ms=1_000,
105+
yield_on_timeout=True,
105106
)
106107
]
107108
for event_type in EventType:

0 commit comments

Comments
 (0)