Handle timeout errors

This commit is contained in:
atse 2023-08-09 11:15:29 +08:00
parent c6815950d2
commit f6dc882d9b
1 changed files with 13 additions and 1 deletions

View File

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