From 400f3a98e861401a20459e6b524a603c52e7ac8a Mon Sep 17 00:00:00 2001 From: atse Date: Tue, 8 Aug 2023 17:16:11 +0800 Subject: [PATCH] Stop polling drift Just waiting for the update_s doesn't take into account the time to execute update_params, and causes time drift. --- pytec/tec_qt.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index ea81260..ee41e4c 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -49,9 +49,11 @@ class ClientWatcher(QObject): super().__init__(parent) async def run(self): + loop = asyncio.get_running_loop() while self.running: + time = loop.time() await self.update_params() - await asyncio.sleep(self.update_s) + await asyncio.sleep(self.update_s - (loop.time() - time)) async def update_params(self): self.fan_update.emit(await tec_client.fan())