From 127dd9da51e13bfbbb82f6cd8bdf3ebf501cede9 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Sat, 20 Jun 2026 23:09:23 +0200 Subject: [PATCH] Don't freeze the GUI thread on disconnect ws_client.disconnect() blocks until the close handshake completes (observed ~10s when the server doesn't ack promptly), and was being called straight from the Connect/Disconnect button's click handler - joining that wait on the GUI thread, so the click appeared to do nothing until the timeout passed. Run it off a throwaway thread instead; on_ws_connect_changed() already flips the button once the disconnect actually finishes. --- client/brewpi_gui.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/brewpi_gui.py b/client/brewpi_gui.py index 8805b6b..de2f094 100755 --- a/client/brewpi_gui.py +++ b/client/brewpi_gui.py @@ -3,6 +3,7 @@ from main_window import Ui_MainWindow from PyQt5 import QtWidgets, QtGui, QtCore import json import sys +import threading import time import matplotlib matplotlib.use("Qt5Agg") @@ -246,7 +247,12 @@ class Window(QtWidgets.QMainWindow, Ui_MainWindow): self.plot_power_set, self.plot_power_eff) def disconnect(self): - self.ws_client.disconnect() + # ws_client.disconnect() blocks until the websocket's close handshake + # completes (or times out, ~10s if the server doesn't ack promptly), + # joining the connection's background thread - run it off a throwaway + # thread so that wait doesn't freeze the GUI. on_ws_connect_changed() + # still flips the button once the disconnect actually finishes. + threading.Thread(target=self.ws_client.disconnect, daemon=True).start() def on_btn_connect_clicked(self): if self.connected: