[PATCH 1/3] Move HW errors processing to the code that runs in the main thread

Vratislav Podzimek vpodzime at redhat.com
Mon Jan 12 14:04:42 UTC 2015


Also rename the run_handleException function to main_thread_handleException
which better explains its purpose.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 pyanaconda/exception.py | 149 ++++++++++++++++++++++++------------------------
 1 file changed, 75 insertions(+), 74 deletions(-)

diff --git a/pyanaconda/exception.py b/pyanaconda/exception.py
index b8b8f4f..9a4e676 100644
--- a/pyanaconda/exception.py
+++ b/pyanaconda/exception.py
@@ -60,7 +60,7 @@ class AnacondaExceptionHandler(ExceptionHandler):
         self._gui_lock = gui_lock
         self._intf_tty_num = tty_num
 
-    def run_handleException(self, dump_info):
+    def _main_loop_handleException(self, dump_info):
         """
         Helper method with one argument only so that it can be registered
         with GLib.idle_add() to run on idle or called from a handler.
@@ -69,8 +69,21 @@ class AnacondaExceptionHandler(ExceptionHandler):
 
         """
 
-        super(AnacondaExceptionHandler, self).handleException(dump_info)
-        return False
+        ty = dump_info.exc_info.type
+        value = dump_info.exc_info.value
+
+        if (issubclass(ty, blivet.errors.StorageError) and value.hardware_fault) \
+                or (issubclass(ty, OSError) and value.errno == errno.EIO):
+            # hardware fault or '[Errno 5] Input/Output error'
+            hw_error_msg = _("The installation was stopped due to what "
+                             "seems to be a problem with your hardware. "
+                             "The exact error message is:\n\n%s.\n\n "
+                             "The installer will now terminate.") % str(value)
+            self.intf.messageWindow(_("Hardware error occured"), hw_error_msg)
+            sys.exit(0)
+        else:
+            super(AnacondaExceptionHandler, self).handleException(dump_info)
+            return False
 
     def handleException(self, dump_info):
         """
@@ -89,78 +102,66 @@ class AnacondaExceptionHandler(ExceptionHandler):
         ty = dump_info.exc_info.type
         value = dump_info.exc_info.value
 
-        if (issubclass(ty, blivet.errors.StorageError) and value.hardware_fault) \
-                or (issubclass(ty, OSError) and value.errno == errno.EIO):
-            # hardware fault or '[Errno 5] Input/Output error'
-            hw_error_msg = _("The installation was stopped due to what "
-                             "seems to be a problem with your hardware. "
-                             "The exact error message is:\n\n%s.\n\n "
-                             "The installer will now terminate.") % str(value)
-            self.intf.messageWindow(_("Hardware error occured"), hw_error_msg)
-            sys.exit(0)
-        else:
-            try:
-                from gi.repository import Gtk
-
-                # XXX: Gtk stopped raising RuntimeError if it fails to
-                # initialize. Horay! But will it stay like this? Let's be
-                # cautious and raise the exception on our own to work in both
-                # cases
-                initialized = Gtk.init_check(None)[0]
-                if not initialized:
-                    raise RuntimeError()
-
-                # Attempt to grab the GUI initializing lock, do not block
-                if not self._gui_lock.acquire(False):
-                    # the graphical interface is running, don't crash it by
-                    # running another one potentially from a different thread
-                    log.debug("Gtk running, queuing exception handler to the "
-                             "main loop")
-                    GLib.idle_add(self.run_handleException, dump_info)
-                else:
-                    log.debug("Gtk not running, starting Gtk and running "
-                             "exception handler in it")
-                    super(AnacondaExceptionHandler, self).handleException(
-                                                            dump_info)
-
-            except (RuntimeError, ImportError):
-                log.debug("Gtk cannot be initialized")
-                # X not running (Gtk cannot be initialized)
-                if threadMgr.in_main_thread():
-                    log.debug("In the main thread, running exception handler")
-                    if (issubclass (ty, CmdlineError)):
-
-                        cmdline_error_msg = _("\nThe installation was stopped due to "
-                                              "incomplete spokes detected while running "
-                                              "in non-interactive cmdline mode. Since there "
-                                              "cannot be any questions in cmdline mode, "
-                                              "edit your kickstart file and retry "
-                                              "installation.\nThe exact error message is: "
-                                              "\n\n%s.\n\nThe installer will now terminate.") % str(value)
-
-                        # since there is no UI in cmdline mode and it is completely
-                        # non-interactive, we can't show a message window asking the user
-                        # to acknowledge the error; instead, print the error out and sleep
-                        # for a few seconds before exiting the installer
-                        print(cmdline_error_msg)
-                        time.sleep(10)
-                        sys.exit(1)
-                    else:
-                        print("\nAn unknown error has occured, look at the "
-                               "/tmp/anaconda-tb* file(s) for more details")
-                        # in the main thread, run exception handler
-                        super(AnacondaExceptionHandler, self).handleException(
-                                                                dump_info)
+        try:
+            from gi.repository import Gtk
+
+            # XXX: Gtk stopped raising RuntimeError if it fails to
+            # initialize. Horay! But will it stay like this? Let's be
+            # cautious and raise the exception on our own to work in both
+            # cases
+            initialized = Gtk.init_check(None)[0]
+            if not initialized:
+                raise RuntimeError()
+
+            # Attempt to grab the GUI initializing lock, do not block
+            if not self._gui_lock.acquire(False):
+                # the graphical interface is running, don't crash it by
+                # running another one potentially from a different thread
+                log.debug("Gtk running, queuing exception handler to the "
+                         "main loop")
+                GLib.idle_add(self._main_loop_handleException, dump_info)
+            else:
+                log.debug("Gtk not running, starting Gtk and running "
+                         "exception handler in it")
+                self._main_loop_handleException(dump_info)
+
+        except (RuntimeError, ImportError):
+            log.debug("Gtk cannot be initialized")
+            # X not running (Gtk cannot be initialized)
+            if threadMgr.in_main_thread():
+                log.debug("In the main thread, running exception handler")
+                if (issubclass (ty, CmdlineError)):
+
+                    cmdline_error_msg = _("\nThe installation was stopped due to "
+                                          "incomplete spokes detected while running "
+                                          "in non-interactive cmdline mode. Since there "
+                                          "cannot be any questions in cmdline mode, "
+                                          "edit your kickstart file and retry "
+                                          "installation.\nThe exact error message is: "
+                                          "\n\n%s.\n\nThe installer will now terminate.") % str(value)
+
+                    # since there is no UI in cmdline mode and it is completely
+                    # non-interactive, we can't show a message window asking the user
+                    # to acknowledge the error; instead, print the error out and sleep
+                    # for a few seconds before exiting the installer
+                    print(cmdline_error_msg)
+                    time.sleep(10)
+                    sys.exit(1)
                 else:
-                    log.debug("In a non-main thread, sending a message with "
-                             "exception data")
-                    # not in the main thread, just send message with exception
-                    # data and let message handler run the exception handler in
-                    # the main thread
-                    exc_info = dump_info.exc_info
-                    hubQ.send_exception((exc_info.type,
-                                         exc_info.value,
-                                         exc_info.stack))
+                    print("\nAn unknown error has occured, look at the "
+                           "/tmp/anaconda-tb* file(s) for more details")
+                    # in the main thread, run exception handler
+                    self._main_loop_handleException(dump_info)
+            else:
+                log.debug("In a non-main thread, sending a message with "
+                         "exception data")
+                # not in the main thread, just send message with exception
+                # data and let message handler run the exception handler in
+                # the main thread
+                exc_info = dump_info.exc_info
+                hubQ.send_exception((exc_info.type,
+                                     exc_info.value,
+                                     exc_info.stack))
 
     def postWriteHook(self, dump_info):
         anaconda = dump_info.object
-- 
2.1.0



More information about the anaconda-patches mailing list