From 759b9e57a1e579ffdcd59ebaacfafeba720cd32f 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 | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pytec/pytec/gui/model/thermostat.py b/pytec/pytec/gui/model/thermostat.py index 5d2292f..6d511fc 100644 --- a/pytec/pytec/gui/model/thermostat.py +++ b/pytec/pytec/gui/model/thermostat.py @@ -40,19 +40,17 @@ 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 ( - Exception, - TimeoutError, - asyncio.exceptions.TimeoutError, - ): - logging.error( - "Encountered an error while updating parameter tree.", - exc_info=True, - ) - _ = self.task.result() + try: + _ = self.task.result() + except ( + Exception, + TimeoutError, + asyncio.exceptions.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)