[master 1/1] Drop multiprocessing for do_transaction (#1208296)

bcl installerbot-noreply at redhat.com
Wed Sep 9 23:02:50 UTC 2015


From: "Brian C. Lane" <bcl at redhat.com>

When running the transaction in a separate process it crashes if you use
a https repo source. There's really no need for threads or processes in
lorax so drop it.

Also switched to using the DNF TransactionProgress API for progress
reporting.
---
 src/pylorax/dnfhelper.py | 26 +++++++++++------------
 src/pylorax/ltmpl.py     | 55 ++++++------------------------------------------
 2 files changed, 19 insertions(+), 62 deletions(-)

diff --git a/src/pylorax/dnfhelper.py b/src/pylorax/dnfhelper.py
index 8e35776..a25d3f6 100644
--- a/src/pylorax/dnfhelper.py
+++ b/src/pylorax/dnfhelper.py
@@ -85,23 +85,23 @@ def start(self, total_files, total_size):
         self.total_size = total_size
 
 
-class LoraxRpmCallback(dnf.callback.LoggingTransactionDisplay):
-    def __init__(self, queue):
+class LoraxRpmCallback(dnf.callback.TransactionProgress):
+    def __init__(self):
         super(LoraxRpmCallback, self).__init__()
-        self._queue = queue
         self._last_ts = None
-        self.cnt = 0
 
-    def event(self, package, action, te_current, te_total, ts_current, ts_total):
-        if action == self.PKG_INSTALL and te_current == 0:
+    def progress(self, package, action, ti_done, ti_total, ts_done, ts_total):
+        if action == self.PKG_INSTALL:
             # do not report same package twice
-            if self._last_ts == ts_current:
+            if self._last_ts == ts_done:
                 return
-            self._last_ts = ts_current
+            self._last_ts = ts_done
 
-            msg = '(%d/%d) %s.%s' % \
-                (ts_current, ts_total, package.name, package.arch)
-            self.cnt += 1
-            self._queue.put(('install', msg))
+            msg = '(%d/%d) %s.%s' % (ts_done, ts_total, package.name, package.arch)
+            logger.info(msg)
         elif action == self.TRANS_POST:
-            self._queue.put(('post', None))
+            msg = "Performing post-installation setup tasks"
+            logger.info(msg)
+
+    def error(self, err_msg):
+        logger.warning(err_msg)
diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py
index 93ecd14..053dec4 100644
--- a/src/pylorax/ltmpl.py
+++ b/src/pylorax/ltmpl.py
@@ -32,15 +32,12 @@
 from pylorax.base import DataHolder
 from pylorax.executils import runcmd, runcmd_output
 from pylorax.imgutils import mkcpio
-import pylorax.output as output
 
 from mako.lookup import TemplateLookup
 from mako.exceptions import text_error_template
 import sys, traceback
 import struct
 import dnf
-import multiprocessing
-import queue
 import collections
 
 class LoraxTemplate(object):
@@ -501,40 +498,12 @@ def removepkg(self, *pkgs):
             else:
                 logger.debug("removepkg %s: no files to remove!", p)
 
-    def get_token_checked(self, process, token_queue):
-        """Try to get token from queue checking that process is still alive"""
-
-        try:
-            # wait at most a minute for the token
-            (token, msg) = token_queue.get(timeout=60)
-        except queue.Empty:
-            if process.is_alive():
-                try:
-                    # process still alive, give it 2 minutes more
-                    (token, msg) = token_queue.get(timeout=120)
-                except queue.Empty:
-                    # waited for 3 minutes and got nothing
-                    raise Exception("The transaction process got stuck somewhere (no message from it in 3 minutes)")
-            else:
-                raise Exception("The transaction process has ended abruptly")
-
-        return (token, msg)
-
     def run_pkg_transaction(self):
         '''
         run_pkg_transaction
           Actually install all the packages requested by previous 'installpkg'
           commands.
         '''
-
-        def do_transaction(base, token_queue):
-            try:
-                display = LoraxRpmCallback(token_queue)
-                base.do_transaction(display=display)
-            except BaseException as e:
-                logger.error("The transaction process has ended abruptly: %s", e)
-                token_queue.put(('quit', str(e)))
-
         try:
             logger.info("Checking dependencies")
             self.dbo.resolve()
@@ -555,24 +524,12 @@ def do_transaction(base, token_queue):
             raise
 
         logger.info("Preparing transaction from installation source")
-        token_queue = multiprocessing.Queue()
-        msgout = output.LoraxOutput()
-        process = multiprocessing.Process(target=do_transaction, args=(self.dbo, token_queue))
-        process.start()
-        (token, msg) = self.get_token_checked(process, token_queue)
-
-        while token not in ('post', 'quit'):
-            if token == 'install':
-                logging.info("%s", msg)
-                msgout.writeline(msg)
-            (token, msg) = self.get_token_checked(process, token_queue)
-
-        if token == 'quit':
-            logger.error("Transaction failed.")
-            raise Exception("Transaction failed")
-
-        logger.info("Performing post-installation setup tasks")
-        process.join()
+        try:
+            display = LoraxRpmCallback()
+            self.dbo.do_transaction(display=display)
+        except BaseException as e:
+            logger.error("The transaction process has ended abruptly: %s", e)
+            raise
 
         # Reset the package sack to pick up the installed packages
         self.dbo.reset(repos=False)


-- 
To view this commit on github, visit https://github.com/rhinstaller/lorax/commit/b3bf61bfddf80bfa7f9b152eb17d9b7b5393ecc5


More information about the anaconda-patches mailing list