From 1b64a88c7580a7f5d87605821bc13bb31b3ac422 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 28c85db..16e51fc 100644 --- a/pytec/pytec/gui/model/thermostat.py +++ b/pytec/pytec/gui/model/thermostat.py @@ -40,15 +40,13 @@ class Thermostat(QObject, metaclass=PropertyMeta): self.task = asyncio.create_task(self.update_params()) while True: if self.task.done(): - if self.task.exception() is not None: - try: - raise self.task.exception() - except asyncio.TimeoutError: - logging.error( - "Encountered an error while updating parameter tree.", - exc_info=True, - ) - _ = self.task.result() + try: + _ = self.task.result() + except asyncio.TimeoutError: + logging.error( + "Encountered an error while updating parameter tree.", + exc_info=True, + ) self.task = asyncio.create_task(self.update_params()) await asyncio.sleep(self._update_s)