From dcf628b5425bffb94664a205e5fea97b19adf86f Mon Sep 17 00:00:00 2001 From: atse Date: Thu, 22 Aug 2024 17:48:24 +0800 Subject: [PATCH] thermostat: Properly register task Also Thermostat.task -> Thermostat._update_params_task --- pytec/pytec/gui/model/thermostat.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pytec/pytec/gui/model/thermostat.py b/pytec/pytec/gui/model/thermostat.py index e370ba1..23f098d 100644 --- a/pytec/pytec/gui/model/thermostat.py +++ b/pytec/pytec/gui/model/thermostat.py @@ -34,22 +34,23 @@ class Thermostat(QObject, metaclass=PropertyMeta): self._watch_task = None self._report_mode_task = None self._poll_for_report = True + self._update_params_task = None super().__init__(parent) async def run(self): - self.task = asyncio.create_task(self.update_params()) + self._update_params_task = asyncio.create_task(self.update_params()) while True: - if self.task.done(): - if self.task.exception() is not None: + if self._update_params_task.done(): + if self._update_params_task.exception() is not None: try: - raise self.task.exception() + raise self._update_params_task.exception() except asyncio.TimeoutError: logging.error( "Encountered an error while polling for information from Thermostat.", exc_info=True, ) - _ = self.task.result() - self.task = asyncio.create_task(self.update_params()) + _ = self._update_params_task.result() + self._update_params_task = asyncio.create_task(self.update_params()) await asyncio.sleep(self._update_s) async def get_hw_rev(self): @@ -83,8 +84,8 @@ class Thermostat(QObject, metaclass=PropertyMeta): await self.set_report_mode(False) self._watch_task.cancel() self._watch_task = None - self.task.cancel() - self.task = None + self._update_params_task.cancel() + self._update_params_task = None async def set_report_mode(self, enabled: bool): self._poll_for_report = not enabled