aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2024-02-12 19:30:00 -0800
committerZac Medico <zmedico@gentoo.org>2024-02-21 07:27:30 -0800
commit414234a218bc79564ab17312d5cc247a4c8091d7 (patch)
tree7618dde9ee5f2c6e87541fc88655cd749d2b5a74
parentSupport PROPERTIES=test_userpriv not to drop perms for tests (diff)
downloadportage-414234a218bc79564ab17312d5cc247a4c8091d7.tar.gz
portage-414234a218bc79564ab17312d5cc247a4c8091d7.tar.bz2
portage-414234a218bc79564ab17312d5cc247a4c8091d7.zip
anydbm: Pickle support for multiprocessing spawn
The egencache usage in ResolverPlayground that was used to trigger bug 924319 triggered a pickling error for AuxdbTestCase.test_anydbm with the multiprocessing spawn start method, so fix the anydbm cache module to omit the unpicklable database object from pickled state, and regenerate it after unpickling. Bug: https://bugs.gentoo.org/924319 Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--lib/portage/cache/anydbm.py17
-rw-r--r--lib/portage/tests/dbapi/test_auxdb.py4
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/portage/cache/anydbm.py b/lib/portage/cache/anydbm.py
index 94a270a48..ad7042ae4 100644
--- a/lib/portage/cache/anydbm.py
+++ b/lib/portage/cache/anydbm.py
@@ -1,4 +1,4 @@
-# Copyright 2005-2020 Gentoo Authors
+# Copyright 2005-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
# Author(s): Brian Harring (ferringb@gentoo.org)
@@ -67,6 +67,21 @@ class database(fs_template.FsBased):
raise cache_errors.InitializationError(self.__class__, e)
self._ensure_access(self._db_path)
+ def __getstate__(self):
+ state = self.__dict__.copy()
+ # These attributes are not picklable, so they are automatically
+ # regenerated after unpickling.
+ state["_database__db"] = None
+ return state
+
+ def __setstate__(self, state):
+ self.__dict__.update(state)
+ mode = "w"
+ if dbm.whichdb(self._db_path) in ("dbm.gnu", "gdbm"):
+ # Allow multiple concurrent writers (see bug #53607).
+ mode += "u"
+ self.__db = dbm.open(self._db_path, mode, self._perms)
+
def iteritems(self):
# dbm doesn't implement items()
for k in self.__db.keys():
diff --git a/lib/portage/tests/dbapi/test_auxdb.py b/lib/portage/tests/dbapi/test_auxdb.py
index 0de0123a5..aac6ce361 100644
--- a/lib/portage/tests/dbapi/test_auxdb.py
+++ b/lib/portage/tests/dbapi/test_auxdb.py
@@ -16,9 +16,7 @@ class AuxdbTestCase(TestCase):
from portage.cache.anydbm import database
except ImportError:
self.skipTest("dbm import failed")
- self._test_mod(
- "portage.cache.anydbm.database", multiproc=False, picklable=False
- )
+ self._test_mod("portage.cache.anydbm.database", multiproc=False, picklable=True)
def test_flat_hash_md5(self):
self._test_mod("portage.cache.flat_hash.md5_database")