|
20 | 20 |
|
21 | 21 | import asyncio |
22 | 22 | import pathlib |
| 23 | +import sys |
23 | 24 | from collections import abc |
24 | 25 | from dataclasses import dataclass |
25 | 26 | from datetime import timedelta |
@@ -159,6 +160,10 @@ def __init__( |
159 | 160 | watch_filter=self._filter_events, |
160 | 161 | force_polling=force_polling, |
161 | 162 | poll_delay_ms=int(polling_interval.total_seconds() * 1_000), |
| 163 | + # Two arguments below are ok for non-Windows systems. |
| 164 | + # For more details, refer awatch documentation. |
| 165 | + rust_timeout=sys.maxsize - 1, |
| 166 | + yield_on_timeout=True, |
162 | 167 | ) |
163 | 168 | self._awatch_stopped_exc: Exception | None = None |
164 | 169 | self._changes: set[FileChange] = set() |
@@ -204,11 +209,16 @@ async def ready(self) -> bool: |
204 | 209 | if self._awatch_stopped_exc is not None: |
205 | 210 | return False |
206 | 211 |
|
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 | + # This is safety heartbeat mechanism for Windows. |
| 214 | + # But on non-Windows systems, we don't need it, so we can ignore it. |
| 215 | + # For more details, refer awatch documentation. |
| 216 | + while len(self._changes) == 0: |
| 217 | + try: |
| 218 | + self._changes = await anext(self._awatch) |
| 219 | + except StopAsyncIteration as err: |
| 220 | + self._awatch_stopped_exc = err |
| 221 | + return False |
212 | 222 |
|
213 | 223 | return True |
214 | 224 |
|
|
0 commit comments