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)