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 446d5c4d22
commit f230a51a52

View File

@ -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)