From bc4b5bb61518db2342a4915d67cb5238480281c0 Mon Sep 17 00:00:00 2001 From: atse Date: Tue, 8 Aug 2023 16:56:36 +0800 Subject: [PATCH] Bail Disconnects everything, stops all polling --- pytec/tec_qt.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 9af0a87..24abf7a 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -557,8 +557,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): @asyncClose async def closeEvent(self, event): - await self._on_connection_changed(False) - await self.client.disconnect() + await self.bail() @asyncSlot() async def on_connect_btn_clicked(self): @@ -576,13 +575,15 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): return await self._on_connection_changed(True) else: - await self._on_connection_changed(False) - await self.client.disconnect() + await self.bail() except (OSError, TimeoutError, asyncio.TimeoutError) as e: # TODO: Remove asyncio.TimeoutError in Python 3.11 logging.error(f"Failed communicating to {host}:{port}: {e}") - await self._on_connection_changed(False) - await self.client.disconnect() + await self.bail() + + async def bail(self): + await self._on_connection_changed(False) + await self.client.disconnect() @pyqtSlot(list) def plot(self, report):