Skip to content

Commit 91e27c6

Browse files
authored
Merge pull request #4115 from grandixximo/fix/gmoccapy-sigterm-robust
gmoccapy: exit on SIGTERM/SIGINT regardless of main-loop state
2 parents f729a61 + 071756a commit 91e27c6

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/emc/usr_intf/gmoccapy/gmoccapy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from common import hal_glib # needed to make our own hal pins
4141
import sys # handle system calls
4242
import os # needed to get the paths and directories
43+
import signal # clean shutdown on SIGTERM/SIGINT
4344
import atexit # needed to register child's to be closed on closing the GUI
4445
import subprocess # to launch onboard and other processes
4546
import tempfile # needed only if the user click new in edit mode to open a new empty file
@@ -6594,6 +6595,18 @@ def _make_hal_pins(self):
65946595
raise SystemExit(res)
65956596

65966597

6598+
# Exit on SIGTERM/SIGINT whether or not a main loop is running.
6599+
# Gtk.main_quit() does nothing outside a running loop, so quit the
6600+
# loop if one is active, otherwise exit the process.
6601+
def _terminate(signum, frame):
6602+
LOG.info("gmoccapy received signal {}, shutting down".format(signum))
6603+
if Gtk.main_level() > 0:
6604+
Gtk.main_quit()
6605+
else:
6606+
sys.exit(0)
6607+
signal.signal(signal.SIGTERM, _terminate)
6608+
signal.signal(signal.SIGINT, _terminate)
6609+
65976610
# start the event loop
65986611
Gtk.main()
65996612

0 commit comments

Comments
 (0)