diff --git a/lib/python/gladevcp/hal_sourceview.py b/lib/python/gladevcp/hal_sourceview.py index 31f98d69fac..06ec019514c 100644 --- a/lib/python/gladevcp/hal_sourceview.py +++ b/lib/python/gladevcp/hal_sourceview.py @@ -55,7 +55,9 @@ def __init__(self, *a, **kw): self.program_length = 0 self.idle_line_reset = True self.buf = self.get_buffer() - self.buf.set_max_undo_levels(20) + # set_max_undo_levels is gone from newer GtkSourceView 4 releases + if hasattr(self.buf, 'set_max_undo_levels'): + self.buf.set_max_undo_levels(20) self.buf.connect('changed', self.update_iter) self.buf.connect('modified-changed', self.modified_changed) self.lm = GtkSource.LanguageManager() diff --git a/src/emc/usr_intf/gmoccapy/gmoccapy.py b/src/emc/usr_intf/gmoccapy/gmoccapy.py index 1e6852dcc90..6910c5741ce 100644 --- a/src/emc/usr_intf/gmoccapy/gmoccapy.py +++ b/src/emc/usr_intf/gmoccapy/gmoccapy.py @@ -68,7 +68,8 @@ def excepthook(exc_type, exc_obj, exc_tb): return try: w = app.widgets.window1 - except NameError: + except Exception: + # app not built (or partially built): parentless dialog w = None lines = traceback.format_exception(exc_type, exc_obj, exc_tb) message ="Found an error!\nThe following information may be useful in troubleshooting:\n\n" + "".join(lines) @@ -81,8 +82,10 @@ def excepthook(exc_type, exc_obj, exc_tb): buttons = Gtk.ButtonsType.OK,) m.show() - m.run() - m.destroy() + try: + m.run() + finally: + m.destroy() sys.excepthook = excepthook @@ -6605,12 +6608,21 @@ def _make_hal_pins(self): # Exit on SIGTERM/SIGINT whether or not a main loop is running. - # Gtk.main_quit() does nothing outside a running loop, so quit the - # loop if one is active, otherwise exit the process. + # A modal dialog's gtk_dialog_run() loop is invisible to + # Gtk.main_quit(): destroy all other toplevels so run() returns and + # the unwind reaches Gtk.main(); force exit as a last resort. + def _force_exit(): + LOG.warning("clean shutdown did not finish, forcing exit") + os._exit(0) + def _terminate(signum, frame): LOG.info("gmoccapy received signal {}, shutting down".format(signum)) if Gtk.main_level() > 0: Gtk.main_quit() + for w in Gtk.Window.list_toplevels(): + if w is not app.widgets.window1: + w.destroy() + GLib.timeout_add(2000, _force_exit) else: sys.exit(0) signal.signal(signal.SIGTERM, _terminate)