Merge pull request #9408 from nimlgen/hcq_progress_during_wait

hcq: reset timer on progress in singal.wait
This commit is contained in:
nimlgen 2025-03-11 19:40:23 +08:00 committed by GitHub
commit 78ebade125
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -246,11 +246,12 @@ class HCQSignal(Generic[DeviceType]):
Args:
value: The value to wait for.
timeout: Maximum time to wait in milliseconds. Defaults to 10s.
timeout: Maximum time to wait in milliseconds. Defaults to 30s.
"""
start_time = int(time.perf_counter() * 1000)
while self.value < value and (time_spent:=int(time.perf_counter() * 1000) - start_time) < timeout:
while (prev_value:=self.value) < value and (time_spent:=int(time.perf_counter() * 1000) - start_time) < timeout:
self._sleep(time_spent)
if self.value != prev_value: start_time = int(time.perf_counter() * 1000) # progress was made, reset timer
if self.value < value: raise RuntimeError(f"Wait timeout: {timeout} ms! (the signal is not set to {value}, but {self.value})")
@contextlib.contextmanager