[oe-commits] [openembedded-core] 04/11: package_ipk|deb: Use oe.utils.multiprocess_launch

git at git.openembedded.org git at git.openembedded.org
Fri Jul 20 10:40:38 UTC 2018


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 40ff72256a9b2f779a9cd196e4b6c56b57f02139
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Thu Jul 19 20:32:44 2018 +0000

    package_ipk|deb: Use oe.utils.multiprocess_launch
    
    The current code had broken exception handling due to the use of a
    "traceback" variable as well as an import. Use the new library code
    for this instead which reduces code duplication and has fixed/improved
    exception handling.
    
    The chdir code can be dropped since any directory changes are in other
    processes now so there is no need for it here and the code no longer
    changes directory.
    
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/classes/package_deb.bbclass | 51 +---------------------------------------
 meta/classes/package_ipk.bbclass | 51 +---------------------------------------
 2 files changed, 2 insertions(+), 100 deletions(-)

diff --git a/meta/classes/package_deb.bbclass b/meta/classes/package_deb.bbclass
index 2e8d17d..6f81591 100644
--- a/meta/classes/package_deb.bbclass
+++ b/meta/classes/package_deb.bbclass
@@ -41,32 +41,6 @@ def debian_arch_map(arch, tune):
     return arch
 
 python do_package_deb () {
-
-    import multiprocessing
-    import traceback
-
-    class DebianWritePkgProcess(multiprocessing.Process):
-        def __init__(self, *args, **kwargs):
-            multiprocessing.Process.__init__(self, *args, **kwargs)
-            self._pconn, self._cconn = multiprocessing.Pipe()
-            self._exception = None
-
-        def run(self):
-            try:
-                multiprocessing.Process.run(self)
-                self._cconn.send(None)
-            except Exception as e:
-                tb = traceback.format_exc()
-                self._cconn.send((e, tb))
-
-        @property
-        def exception(self):
-            if self._pconn.poll():
-                self._exception = self._pconn.recv()
-            return self._exception
-
-    oldcwd = os.getcwd()
-
     packages = d.getVar('PACKAGES')
     if not packages:
         bb.debug(1, "PACKAGES not defined, nothing to package")
@@ -76,30 +50,7 @@ python do_package_deb () {
     if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK):
         os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"))
 
-    max_process = int(d.getVar("BB_NUMBER_THREADS") or os.cpu_count() or 1)
-    launched = []
-    error = None
-    pkgs = packages.split()
-    while not error and pkgs:
-        if len(launched) < max_process:
-            p = DebianWritePkgProcess(target=deb_write_pkg, args=(pkgs.pop(), d))
-            p.start()
-            launched.append(p)
-        for q in launched:
-            # The finished processes are joined when calling is_alive()
-            if not q.is_alive():
-                launched.remove(q)
-            if q.exception:
-                error, traceback = q.exception
-                break
-
-    for p in launched:
-        p.join()
-
-    os.chdir(oldcwd)
-
-    if error:
-        raise error
+    oe.utils.multiprocess_launch(deb_write_pkg, packages.split(), d, extraargs=(d,))
 }
 do_package_deb[vardeps] += "deb_write_pkg"
 do_package_deb[vardepsexclude] = "BB_NUMBER_THREADS"
diff --git a/meta/classes/package_ipk.bbclass b/meta/classes/package_ipk.bbclass
index a0b34fa..5eb910c 100644
--- a/meta/classes/package_ipk.bbclass
+++ b/meta/classes/package_ipk.bbclass
@@ -17,32 +17,6 @@ OPKG_ARGS += "${@['', '--add-exclude ' + ' --add-exclude '.join((d.getVar('PACKA
 OPKGLIBDIR = "${localstatedir}/lib"
 
 python do_package_ipk () {
-    import multiprocessing
-    import traceback
-
-    class IPKWritePkgProcess(multiprocessing.Process):
-        def __init__(self, *args, **kwargs):
-            multiprocessing.Process.__init__(self, *args, **kwargs)
-            self._pconn, self._cconn = multiprocessing.Pipe()
-            self._exception = None
-
-        def run(self):
-            try:
-                multiprocessing.Process.run(self)
-                self._cconn.send(None)
-            except Exception as e:
-                tb = traceback.format_exc()
-                self._cconn.send((e, tb))
-
-        @property
-        def exception(self):
-            if self._pconn.poll():
-                self._exception = self._pconn.recv()
-            return self._exception
-
-
-    oldcwd = os.getcwd()
-
     workdir = d.getVar('WORKDIR')
     outdir = d.getVar('PKGWRITEDIRIPK')
     tmpdir = d.getVar('TMPDIR')
@@ -61,30 +35,7 @@ python do_package_ipk () {
     if os.access(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"), os.R_OK):
         os.unlink(os.path.join(tmpdir, "stamps", "IPK_PACKAGE_INDEX_CLEAN"))
 
-    max_process = int(d.getVar("BB_NUMBER_THREADS") or os.cpu_count() or 1)
-    launched = []
-    error = None
-    pkgs = packages.split()
-    while not error and pkgs:
-        if len(launched) < max_process:
-            p = IPKWritePkgProcess(target=ipk_write_pkg, args=(pkgs.pop(), d))
-            p.start()
-            launched.append(p)
-        for q in launched:
-            # The finished processes are joined when calling is_alive()
-            if not q.is_alive():
-                launched.remove(q)
-            if q.exception:
-                error, traceback = q.exception
-                break
-
-    for p in launched:
-        p.join()
-
-    os.chdir(oldcwd)
-
-    if error:
-        raise error
+    oe.utils.multiprocess_launch(ipk_write_pkg, packages.split(), d, extraargs=(d,))
 }
 do_package_ipk[vardeps] += "ipk_write_pkg"
 do_package_ipk[vardepsexclude] = "BB_NUMBER_THREADS"

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list