Skip to content

Commit 7351e0e

Browse files
authored
Merge pull request #4078 from grandixximo/fix/qtvcp-sigterm-clean-exit
qtvcp: exit cleanly on SIGTERM/SIGINT
2 parents c3caef5 + bf37860 commit 7351e0e

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/emc/usr_intf/qtvcp/qtvcp.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,19 @@ def __init__(self):
448448
window.setWindowTitle(INITITLE)
449449

450450
# catch control c and terminate signals
451-
signal.signal(signal.SIGTERM, self.shutdown)
452-
signal.signal(signal.SIGINT, self.shutdown)
451+
# Quit the Qt event loop on the signal so APP.exec() returns and the
452+
# shutdown() below runs the normal cleanup once. Calling shutdown()
453+
# directly from the handler would clean up but leave the loop running.
454+
# Quitting the loop also bypasses the window-close confirmation dialog,
455+
# which is correct for a terminate request and leaves that interactive
456+
# feature untouched. Qt's C++ event loop does not return to Python often
457+
# enough to run Python signal handlers, so a periodic no-op timer yields
458+
# to the interpreter to let them fire.
459+
signal.signal(signal.SIGTERM, lambda *a: APP.quit())
460+
signal.signal(signal.SIGINT, lambda *a: APP.quit())
461+
self._signal_timer = QtCore.QTimer()
462+
self._signal_timer.timeout.connect(lambda: None)
463+
self._signal_timer.start(200)
453464

454465
# check for handler file and if it has 'before_loop' function in
455466
# ineach screen/embedded panel. (screen should be last)

0 commit comments

Comments
 (0)