commit:     c65d2d8b6c17d849e85f8c13c1a287ff1a07ccbd
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Feb  4 07:22:37 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Feb  4 08:27:37 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c65d2d8b

process.spawn: Avoid os.environ pickling error

This error was observed when pickling os.environ for
muliprocessing start method "spawn" after set_term_size
was updated to use returnproc:

  File "/usr/lib/python3.12/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object '_createenviron.<locals>.encode'. Did 
you mean: '_download_dir'?

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

 lib/portage/process.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/portage/process.py b/lib/portage/process.py
index 01426179d7..b223ecb887 100644
--- a/lib/portage/process.py
+++ b/lib/portage/process.py
@@ -527,6 +527,9 @@ def spawn(
         mycommand = mycommand.split()
 
     env = os.environ if env is None else env
+    # Sometimes os.environ can fail to pickle as shown in bug 923750
+    # comment 4, so copy it to a dict.
+    env = env if isinstance(env, dict) else dict(env)
 
     env_stats = None
     if warn_on_large_env:

Reply via email to