Skip to content

gmoccapy: fix SIGTERM/SIGINT hang while a modal dialog is up - #4501

Merged
grandixximo merged 1 commit into
LinuxCNC:masterfrom
grandixximo:gmoccapy-quit-4500
Sep 5, 2026
Merged

gmoccapy: fix SIGTERM/SIGINT hang while a modal dialog is up#4501
grandixximo merged 1 commit into
LinuxCNC:masterfrom
grandixximo:gmoccapy-quit-4500

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

Fixes #4500.

Problem

The ui-smoke gmoccapy-quit test intermittently fails with UI_SMOKE_QUIT_FAIL: GUI still alive 15s after SIGTERM, and c-morley confirmed the same lockup interactively: gmoccapy sometimes refuses to close and has to be killed.

Root cause: GTK3's gtk_dialog_run() spins a private GMainLoop that Gtk.main_quit() cannot reach. When SIGTERM/SIGINT arrives while any modal dialog is up, the handler flags the outer Gtk.main() for exit, but that loop cannot unwind until the dialog returns, and the dialog waits for an OK click that never comes on an unattended machine or a headless CI runner. The process then survives until SIGKILL.

The trigger on the CI runner was an AttributeError during widget construction: newer GtkSourceView 4 releases dropped set_max_undo_levels(), and the exception popped gmoccapy's modal "Found an error!" dialog from the excepthook.

Fix

In the SIGTERM/SIGINT handler: after Gtk.main_quit(), destroy every toplevel except the main window. Destroying a dialog makes its gtk_dialog_run() return, so the unwind proceeds to the outer loop and the process exits through the normal path (atexit handlers, HAL cleanup). A forced os._exit() after 2s remains as a last resort. This covers not just the excepthook dialog but every modal dialog gmoccapy opens (entry, yes/no, system dialogs).

Also:

  • hal_sourceview.py: guard the set_max_undo_levels() call with hasattr() so newer GtkSourceView 4 no longer raises during construction.
  • excepthook: catch any exception (not just NameError) when fetching the parent window, so an error raised before or during app construction is reported instead of being lost to a second exception inside the hook; destroy the dialog via try/finally.

Testing

Reproduced the exact CI failure locally (GUI still alive 15s after SIGTERM) by injecting an exception into the running main loop under full CPU load. With the fix, the same scenario exits 1-3s after SIGTERM across repeated loaded runs, and the normal no-dialog quit path is unchanged (1s).

A modal dialog's gtk_dialog_run() loop is invisible to Gtk.main_quit(), so the GUI survived SIGTERM and the ui-smoke gmoccapy-quit test timed out. _terminate now destroys all other toplevels so run() returns and the unwind proceeds, with a forced exit as backstop.

Also guard set_max_undo_levels() in hal_sourceview (dropped by newer GtkSourceView 4; the AttributeError popped the modal error dialog on CI), and harden the excepthook against a partially built app object.
@grandixximo
grandixximo merged commit 8bf4605 into LinuxCNC:master Sep 5, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed ui-smoke/gmoccapy-quit on timeout?

1 participant