From f230a51a52e57a0a2795d07b704ef2f06328a642 Mon Sep 17 00:00:00 2001 From: atse Date: Tue, 9 Jul 2024 12:27:35 +0800 Subject: [PATCH] Correct exception catching asyncio.Task.result() is simply going to throw the exception in asyncio.Task.exception(), there is no need to manually throw it. --- pytec/pytec/gui/model/thermostat.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pytec/pytec/gui/model/thermostat.py b/pytec/pytec/gui/model/thermostat.py index 7689a2f..1750a83 100644 --- a/pytec/pytec/gui/model/thermostat.py +++ b/pytec/pytec/gui/model/thermostat.py @@ -41,15 +41,13 @@ class Thermostat(QObject, metaclass=PropertyMeta): self._update_params_task = asyncio.create_task(self.update_params()) while True: if self._update_params_task.done(): - if self.task.exception() is not None: - try: - 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() + try: + _ = self._update_params_task.result() + except asyncio.TimeoutError: + logging.error( + "Encountered an error while polling for information from Thermostat.", + exc_info=True, + ) self._update_params_task = asyncio.create_task(self.update_params()) await asyncio.sleep(self._update_s)