Blob Blame History Raw
From 9271503c339b08b4cdb45e048bf73b75f6255752 Mon Sep 17 00:00:00 2001
From: Jiri Konecny <jkonecny@redhat.com>
Date: Fri, 1 Sep 2017 13:14:56 +0200
Subject: [PATCH] Fix catch TUI not main thread exceptions

Exception which are not in a main thread was passed to the hubQ which is
not used anymore in Simpleline. To resolve this issue, exceptions are
now enqueued as ExceptionSignal.
---
 anaconda.spec.in                  |  2 +-
 pyanaconda/exception.py           | 55 +++++++++++++++++++++++++++------------
 pyanaconda/ui/tui/hubs/summary.py |  2 +-
 3 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/anaconda.spec.in b/anaconda.spec.in
index 8d2048f95..9690c32a5 100644
--- a/anaconda.spec.in
+++ b/anaconda.spec.in
@@ -40,7 +40,7 @@ Source0: %{name}-%{version}.tar.bz2
 %define pykickstartver 2.36-1
 %define pypartedver 2.5-2
 %define rpmver 4.10.0
-%define simplelinever 0.4-1
+%define simplelinever 0.5-1
 %define utillinuxver 2.15.1
 
 BuildRequires: audit-libs-devel
diff --git a/pyanaconda/exception.py b/pyanaconda/exception.py
index cf1f0b762..212ee7414 100644
--- a/pyanaconda/exception.py
+++ b/pyanaconda/exception.py
@@ -17,28 +17,34 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-from meh import Config
-from meh.handler import ExceptionHandler
-from meh.dump import ReverseExceptionDump
-from pyanaconda import iutil, kickstart
-import sys
+import errno
+import glob
+import gi
 import os
+import re
 import shutil
+import sys
 import time
-import re
-import errno
-import glob
 import traceback
+
 import blivet.errors
-from pyanaconda.errors import NonInteractiveError
-from pyanaconda.ui.communication import hubQ
-from pyanaconda.constants import THREAD_EXCEPTION_HANDLING_TEST, IPMI_FAILED
-from pyanaconda.threading import threadMgr
-from pyanaconda.i18n import _
+
+from meh import Config
+from meh.dump import ReverseExceptionDump
+from meh.handler import ExceptionHandler
+
 from pyanaconda import flags
+from pyanaconda import iutil, kickstart
 from pyanaconda import startup_utils
+from pyanaconda.constants import THREAD_EXCEPTION_HANDLING_TEST, IPMI_FAILED
+from pyanaconda.errors import NonInteractiveError
+from pyanaconda.i18n import _
+from pyanaconda.threading import threadMgr
+from pyanaconda.ui.communication import hubQ
+
+from simpleline import App
+from simpleline.event_loop.signals import ExceptionSignal
 
-import gi
 gi.require_version("GLib", "2.0")
 
 from gi.repository import GLib
@@ -46,6 +52,7 @@ from gi.repository import GLib
 from pyanaconda.anaconda_loggers import get_module_logger
 log = get_module_logger(__name__)
 
+
 class AnacondaReverseExceptionDump(ReverseExceptionDump):
 
     @property
@@ -70,6 +77,7 @@ class AnacondaReverseExceptionDump(ReverseExceptionDump):
         else:
             return ""
 
+
 class AnacondaExceptionHandler(ExceptionHandler):
 
     def __init__(self, confObj, intfClass, exnClass, tty_num, gui_lock, interactive):
@@ -190,9 +198,16 @@ class AnacondaExceptionHandler(ExceptionHandler):
                 # 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))
+                # new Simpleline package is now used in TUI. Look if Simpleline is
+                # initialized or if this is some fallback from GTK or other stuff.
+                if App.is_initialized():
+                    # if Simpleline is initialized enqueue exception there
+                    loop = App.get_event_loop()
+                    loop.enqueue_signal(ExceptionSignal(App.get_scheduler(), exception_info=exc_info))
+                else:
+                    hubQ.send_exception((exc_info.type,
+                                         exc_info.value,
+                                         exc_info.stack))
 
     def postWriteHook(self, dump_info):
         anaconda = dump_info.object
@@ -243,6 +258,7 @@ class AnacondaExceptionHandler(ExceptionHandler):
                 and self._intf_tty_num != 1:
             iutil.vtActivate(self._intf_tty_num)
 
+
 def initExceptionHandling(anaconda):
     file_list = ["/tmp/anaconda.log", "/tmp/packaging.log",
                  "/tmp/program.log", "/tmp/storage.log", "/tmp/ifcfg.log",
@@ -298,16 +314,19 @@ def initExceptionHandling(anaconda):
 
     return conf
 
+
 def lsblk_callback():
     """Callback to get info about block devices."""
 
     return iutil.execWithCapture("lsblk", ["--perms", "--fs", "--bytes"])
 
+
 def nmcli_dev_list_callback():
     """Callback to get info about network devices."""
 
     return iutil.execWithCapture("nmcli", ["device", "show"])
 
+
 def journalctl_callback():
     """Callback to get logs from journalctl."""
 
@@ -322,6 +341,7 @@ def journalctl_callback():
 
     return ret
 
+
 def list_addons_callback():
     """
     Callback to get info about the addons potentially affecting Anaconda's
@@ -333,6 +353,7 @@ def list_addons_callback():
     addon_pkgs = glob.glob("/usr/share/anaconda/addons/*")
     return ", ".join(addon.rsplit("/", 1)[1] for addon in addon_pkgs)
 
+
 def test_exception_handling():
     """
     Function that can be used for testing exception handling in anaconda. It
diff --git a/pyanaconda/ui/tui/hubs/summary.py b/pyanaconda/ui/tui/hubs/summary.py
index 65459e043..1d8036439 100644
--- a/pyanaconda/ui/tui/hubs/summary.py
+++ b/pyanaconda/ui/tui/hubs/summary.py
@@ -61,7 +61,7 @@ class SummaryHub(TUIHub):
             sys.stdout.flush()
             spokes = self._spokes.values()
             while not all(spoke.ready for spoke in spokes):
-                # Catch any asyncronous events (like storage crashing)
+                # Catch any asynchronous events (like storage crashing)
                 loop = App.get_event_loop()
                 loop.process_signals()
                 sys.stdout.write('.')
-- 
2.13.5