From f6dc882d9b41f24177360e6da774445e855f9e4f Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 9 Aug 2023 11:15:29 +0800 Subject: [PATCH] Handle timeout errors --- pytec/tec_qt.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index d699265..e8c097f 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -77,6 +77,17 @@ def get_argparser(): return parser +class WrappedClient(QObject, Client): + connection_error = pyqtSignal() + + async def _read_line(self): + try: + return await super()._read_line() + except (OSError, TimeoutError, asyncio.TimeoutError) as e: # TODO: Remove asyncio.TimeoutError in Python 3.11 + logging.error("Client connection error, disconnecting", exc_info=True) + self.connection_error.emit() + + class ClientWatcher(QObject): fan_update = pyqtSignal(dict) pwm_update = pyqtSignal(list) @@ -169,7 +180,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): self.hw_rev_data = None - self.client = Client() + self.client = WrappedClient() + self.client.connection_error.connect(self.bail) self.client_watcher = ClientWatcher(self, self.client, self.report_refresh_spin.value()) self.client_watcher.fan_update.connect(self.fan_update) self.client_watcher.report_update.connect(self.plot)