From b0c30d128ed2d47563bfefe30cb28ca9a148effb Mon Sep 17 00:00:00 2001 From: atse Date: Thu, 22 Aug 2024 11:43:21 +0800 Subject: [PATCH] try-block --- pytec/tec_qt.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 41f183f..54d0cd0 100755 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -252,20 +252,23 @@ class MainWindow(QtWidgets.QMainWindow): self.conn_menu.host_set_line.setEnabled(False) self.conn_menu.port_set_spin.setEnabled(False) - try: - self._connecting_task = asyncio.create_task( - asyncio.wait_for(self.thermostat.start_session(host=host, port=port), timeout=5) + self._connecting_task = asyncio.create_task( + asyncio.wait_for( + self.thermostat.start_session(host=host, port=port), timeout=5 ) + ) + try: await self._connecting_task except (OSError, asyncio.TimeoutError): await self.bail() return except asyncio.CancelledError: return + else: + await self._on_connection_changed(True) finally: self._connecting_task = None - await self._on_connection_changed(True) else: if self._connecting_task is not None: self._connecting_task.cancel()