Fail safe, not dead: bound the HID cancel wait, isolate sensor failures, keep the fan worker alive
- hid.py: after a timed-out HID operation, wait at most 1 s for the driver to finish the cancelled IRP; if it does not, mark the channel broken so the caller's reconnect path closes it instead of blocking forever on a wedged device. Keep abandoned OVERLAPPED/buffer references alive until close so a late IRP completion cannot write into reused memory. Check CreateEventW. - telemetry/service.py: read each source (CPU, GPU, system power, GPU memory) independently; a failing source now costs only its own readings instead of the whole sample, logged at most once a minute per source. - sensors.py: the Commander PRO iCUE ownership check runs inside a guard; if ownership cannot be established the device is released rather than risking swapped replies (and the failure no longer escapes into the sample). - cooling/control.py: an unexpected exception no longer ends fan control for the life of the process; fail safe, log at most once a minute, retry with a fresh sensor object after 5 s. failsafe() no longer raises, and control errors back off 5 s instead of re-opening the device every second.
This commit is contained in:
1 parent
7356809c0a
commit
d637d46777
5 files changed
+102
-26
No files matched your search
@@ -50,15 +50,29 @@ class Telemetry:
|
||||
self._history: collections.deque[tuple] = collections.deque(maxlen=int(HISTORY_SECONDS / interval))
|
||||
self._listeners: list[Callable[[Sample], None]] = []
|
||||
self._seq = 0
|
||||
self._last_failure: dict[str, float] = {}
|
||||
|
||||
def subscribe(self, listener: Callable[[Sample], None]) -> None:
|
||||
self._listeners.append(listener)
|
||||
|
||||
def read(self) -> Sample:
|
||||
c, g = self.cpu.read(), self.gpu.read()
|
||||
p = self.system.read(c, g)
|
||||
"""Read every source independently: one failing source costs only its own readings."""
|
||||
c = self._source("CPU sensors", self.cpu.read, Readings())
|
||||
g = self._source("GPU sensors", self.gpu.read, Readings())
|
||||
p = self._source("system power", self.system.read, PowerReadings(), c, g)
|
||||
vram = self._source("GPU memory", self.gpu.memory, None)
|
||||
self._seq += 1
|
||||
return Sample(self._seq, time.time(), c, g, p, self.gpu.memory())
|
||||
return Sample(self._seq, time.time(), c, g, p, vram)
|
||||
|
||||
def _source(self, name: str, read: Callable, fallback, *args):
|
||||
try:
|
||||
return read(*args)
|
||||
except Exception as e:
|
||||
# The loop retries every second, so log each failing source at most once a minute.
|
||||
if time.monotonic() - self._last_failure.get(name, -1e9) >= 60:
|
||||
self._last_failure[name] = time.monotonic()
|
||||
log.warning("%s read failed; continuing without it: %s", name, e, exc_info=True)
|
||||
return fallback
|
||||
|
||||
def run(self, stop: threading.Event) -> None:
|
||||
while not stop.is_set():
|
||||
|
||||
Reference in new issue
Block a user