commit:     c41d109b121feb0bf6199b4082a35799fdc547b9
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Oct 22 08:28:39 2023 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Oct 22 08:30:50 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c41d109b

vardbapi.unpack_metadata: Make compatible with spawn start method

This solves the following error with the multiprocessing spawn start
method:

AttributeError: Can't pickle local object 
'vardbapi.unpack_metadata.<locals>.async_copy'

Bug: https://bugs.gentoo.org/916108
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/dbapi/vartree.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/portage/dbapi/vartree.py b/lib/portage/dbapi/vartree.py
index 88fc525771..a80d3bc0e3 100644
--- a/lib/portage/dbapi/vartree.py
+++ b/lib/portage/dbapi/vartree.py
@@ -1003,6 +1003,13 @@ class vardbapi(dbapi):
                     pass
         self._bump_mtime(cpv)
 
+    @staticmethod
+    def _async_copy(dbdir, dest_dir):
+        for parent, dirs, files in os.walk(dbdir, onerror=_raise_exc):
+            for key in files:
+                shutil.copy(os.path.join(parent, key), os.path.join(dest_dir, 
key))
+            break
+
     async def unpack_metadata(self, pkg, dest_dir, loop=None):
         """
         Unpack package metadata to a directory. This method is a coroutine.
@@ -1018,14 +1025,9 @@ class vardbapi(dbapi):
         else:
             cpv = pkg.mycpv
         dbdir = self.getpath(cpv)
-
-        def async_copy():
-            for parent, dirs, files in os.walk(dbdir, onerror=_raise_exc):
-                for key in files:
-                    shutil.copy(os.path.join(parent, key), 
os.path.join(dest_dir, key))
-                break
-
-        await loop.run_in_executor(ForkExecutor(loop=loop), async_copy)
+        await loop.run_in_executor(
+            ForkExecutor(loop=loop), self._async_copy, dbdir, dest_dir
+        )
 
     async def unpack_contents(
         self,

Reply via email to