mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-06-24 02:14:17 +00:00
Merge pull request #9408 from nimlgen/hcq_progress_during_wait
hcq: reset timer on progress in singal.wait
This commit is contained in:
commit
78ebade125
1 changed files with 3 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue