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.
This commit is contained in:
atse 2024-07-09 12:27:35 +08:00
parent 9aaadfa6e6
commit 3369ed2c77

View File

@ -40,9 +40,8 @@ class Thermostat(QObject, metaclass=PropertyMeta):
self.task = asyncio.create_task(self.update_params()) self.task = asyncio.create_task(self.update_params())
while True: while True:
if self.task.done(): if self.task.done():
if self.task.exception() is not None:
try: try:
raise self.task.exception() _ = self.task.result()
except ( except (
Exception, Exception,
TimeoutError, TimeoutError,
@ -52,7 +51,6 @@ class Thermostat(QObject, metaclass=PropertyMeta):
"Encountered an error while updating parameter tree.", "Encountered an error while updating parameter tree.",
exc_info=True, exc_info=True,
) )
_ = self.task.result()
self.task = asyncio.create_task(self.update_params()) self.task = asyncio.create_task(self.update_params())
await asyncio.sleep(self._update_s) await asyncio.sleep(self._update_s)