From c142168019f61776ba612fa05ac6a0adb17ba1e2 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 19 Oct 2026 19:23:11 +0200 Subject: Fix crash when closing the Jobs tab during a running job Closing the tab killed the job-follow process, whose finished signal arrived after the tab was deleted; the slot touched dead widgets and PyQt6 aborted the whole application on the unhandled exception. stop() now disconnects the process before killing it. A sys.excepthook logs any future slot exception to stderr instead of aborting. Co-Authored-By: Claude Opus 5.5 --- sb_builder/__main__.py | 3 +++ sb_builder/jobs.py | 4 ++++ tests/test_gui.py | 27 ++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/sb_builder/__main__.py b/sb_builder/__main__.py index 5a78b64..ae8e89a 100644 --- a/sb_builder/__main__.py +++ b/sb_builder/__main__.py @@ -17,6 +17,7 @@ """Entry point: python3 -m sb_builder.""" import sys +import traceback from PyQt6.QtWidgets import QApplication, QMessageBox @@ -26,6 +27,8 @@ from .remote import Remote def main(): + # PyQt aborts on an exception escaping a slot unless a hook is set: log it instead + sys.excepthook = traceback.print_exception app = QApplication(sys.argv) app.setApplicationName("sb-builder") cfg, err = config.load() diff --git a/sb_builder/jobs.py b/sb_builder/jobs.py index e0f906b..bcbd812 100644 --- a/sb_builder/jobs.py +++ b/sb_builder/jobs.py @@ -124,7 +124,11 @@ class JobsTab(QWidget): def stop(self): if self.proc: p, self.proc = self.proc, None + # disconnect first: finished arrives later, maybe after this tab is deleted + p.readyReadStandardOutput.disconnect() + p.finished.disconnect() p.kill() + p.deleteLater() def start(self, *args): self.remote.call(self._started, "job-start", *args) diff --git a/tests/test_gui.py b/tests/test_gui.py index 95f9afb..16b83c0 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -23,12 +23,13 @@ import importlib.machinery # noqa: E402 import importlib.util # noqa: E402 import sys # noqa: E402 import tempfile # noqa: E402 +import time # noqa: E402 import unittest # noqa: E402 ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") sys.path.insert(0, ROOT) -from PyQt6.QtCore import QObject, pyqtSignal # noqa: E402 +from PyQt6.QtCore import QCoreApplication, QEvent, QObject, QProcess, pyqtSignal # noqa: E402 from PyQt6.QtWidgets import QApplication # noqa: E402 from sb_builder import VERSION, config # noqa: E402 @@ -156,6 +157,30 @@ class SmokeTest(unittest.TestCase): self.assertEqual(w.conn.text(), "● VM off") self.assertFalse(w.vm_btn.isHidden()) + def test_close_jobs_tab_while_following(self): + # regression: the follow process ended after the tab was deleted, its + # finished slot touched dead widgets and PyQt aborted the app + w, remote = self.window(jobs=({"jobs": [JOB]}, None)) + procs = QObject() + self.addCleanup(procs.deleteLater) + + def follow(jid, offset): + p = QProcess(procs) + p.start("sleep", ["5"]) + return p + + remote.follow = follow + w.poll_jobs() + jobs = w.open_jobs() + jobs.select(JOB["id"]) + self.assertIsNotNone(jobs.proc) + w._close_tab(w.tabs.indexOf(jobs)) + QCoreApplication.sendPostedEvents(None, QEvent.Type.DeferredDelete.value) + end = time.monotonic() + 1 + while time.monotonic() < end: # let the killed process report in + app.processEvents() + self.assertIsNone(w.jobs_tab) + def test_log_carriage_return(self): w, _ = self.window() jobs = w.open_jobs() -- cgit v1.2.3