From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1597474-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 8E3CC15815E
	for <garchives@archives.gentoo.org>; Mon,  5 Feb 2024 01:03:24 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id B09F12BC017;
	Mon,  5 Feb 2024 01:03:23 +0000 (UTC)
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 952C72BC017
	for <gentoo-commits@lists.gentoo.org>; Mon,  5 Feb 2024 01:03:23 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 7AB88343173
	for <gentoo-commits@lists.gentoo.org>; Mon,  5 Feb 2024 01:03:22 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id D6FD014AB
	for <gentoo-commits@lists.gentoo.org>; Mon,  5 Feb 2024 01:03:20 +0000 (UTC)
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org>
Message-ID: <1707035257.c65d2d8b6c17d849e85f8c13c1a287ff1a07ccbd.zmedico@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/
X-VCS-Repository: proj/portage
X-VCS-Files: lib/portage/process.py
X-VCS-Directories: lib/portage/
X-VCS-Committer: zmedico
X-VCS-Committer-Name: Zac Medico
X-VCS-Revision: c65d2d8b6c17d849e85f8c13c1a287ff1a07ccbd
X-VCS-Branch: master
Date: Mon,  5 Feb 2024 01:03:20 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: d81a9c4e-d40d-440e-b8a9-a5e1f23a46bc
X-Archives-Hash: 23c78cb0286d62d454a3c924f7a36521

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: