From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 15C68158089 for ; Thu, 5 Oct 2023 05:45:20 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 54A3D2BC02E; Thu, 5 Oct 2023 05:45:19 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 34E362BC02E for ; Thu, 5 Oct 2023 05:45:19 +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 3EBF6335CD2 for ; Thu, 5 Oct 2023 05:45:17 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6D1BC9AC for ; Thu, 5 Oct 2023 05:45:15 +0000 (UTC) From: "Zac Medico" 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" Message-ID: <1696483138.2ccc08e3b629d3f56f028cd767ebd5ff1a8edaf1.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/dbapi/_MergeProcess.py X-VCS-Directories: lib/portage/dbapi/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 2ccc08e3b629d3f56f028cd767ebd5ff1a8edaf1 X-VCS-Branch: master Date: Thu, 5 Oct 2023 05:45:15 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 2d4ec2bf-cd8b-460d-a0b6-32258bc64cbe X-Archives-Hash: 2ae96ee1c40ded8b78a89adeb20f056e commit: 2ccc08e3b629d3f56f028cd767ebd5ff1a8edaf1 Author: Zac Medico gentoo org> AuthorDate: Thu Oct 5 04:43:50 2023 +0000 Commit: Zac Medico gentoo org> CommitDate: Thu Oct 5 05:18:58 2023 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=2ccc08e3 MergeProcess: Migrate to ForkProcess target parameter Bug: https://bugs.gentoo.org/915099 Signed-off-by: Zac Medico gentoo.org> lib/portage/dbapi/_MergeProcess.py | 73 +++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/lib/portage/dbapi/_MergeProcess.py b/lib/portage/dbapi/_MergeProcess.py index 7c018222fe..012435dce3 100644 --- a/lib/portage/dbapi/_MergeProcess.py +++ b/lib/portage/dbapi/_MergeProcess.py @@ -1,6 +1,7 @@ -# Copyright 2010-2020 Gentoo Authors +# Copyright 2010-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 +import functools import io import multiprocessing import platform @@ -73,6 +74,20 @@ class MergeProcess(ForkProcess): self.fd_pipes.setdefault(0, portage._get_stdin().fileno()) self.log_filter_file = self.settings.get("PORTAGE_LOG_FILTER_FILE_CMD") + self.target = functools.partial( + self._target, + lambda: self._counter, + lambda: self._elog_reader_fd, + lambda: self._dblink, + self.infloc, + self.mydbapi, + self.myebuild, + self.pkgloc, + self.prev_mtimes, + self.settings, + self.unmerge, + self.vartree.dbapi, + ) super()._start() def _lock_vdb(self): @@ -197,13 +212,29 @@ class MergeProcess(ForkProcess): return pids - def _run(self): - os.close(self._elog_reader_fd) - counter = self._counter - mylink = self._dblink - portage.output.havecolor = not no_color(self.settings) + @staticmethod + def _target( + get_counter, + get_elog_reader_fd, + get_mylink, + infloc, + mydbapi, + myebuild, + pkgloc, + prev_mtimes, + settings, + unmerge, + vardb, + ): + """ + TODO: Make all arguments picklable for the multiprocessing spawn start method. + """ + os.close(get_elog_reader_fd()) + counter = get_counter() + mylink = get_mylink() + portage.output.havecolor = not no_color(settings) # Avoid wastful updates of the vdb cache. - self.vartree.dbapi._flush_cache_enabled = False + vardb._flush_cache_enabled = False # In this subprocess we don't want PORTAGE_BACKGROUND to # suppress stdout/stderr output since they are pipes. We @@ -211,21 +242,21 @@ class MergeProcess(ForkProcess): # already be opened by the parent process, so we set the # "subprocess" value for use in conditional logging code # involving PORTAGE_LOG_FILE. - if not self.unmerge: + if not unmerge: # unmerge phases have separate logs - if self.settings.get("PORTAGE_BACKGROUND") == "1": - self.settings["PORTAGE_BACKGROUND_UNMERGE"] = "1" + if settings.get("PORTAGE_BACKGROUND") == "1": + settings["PORTAGE_BACKGROUND_UNMERGE"] = "1" else: - self.settings["PORTAGE_BACKGROUND_UNMERGE"] = "0" - self.settings.backup_changes("PORTAGE_BACKGROUND_UNMERGE") - self.settings["PORTAGE_BACKGROUND"] = "subprocess" - self.settings.backup_changes("PORTAGE_BACKGROUND") + settings["PORTAGE_BACKGROUND_UNMERGE"] = "0" + settings.backup_changes("PORTAGE_BACKGROUND_UNMERGE") + settings["PORTAGE_BACKGROUND"] = "subprocess" + settings.backup_changes("PORTAGE_BACKGROUND") rval = 1 - if self.unmerge: + if unmerge: if not mylink.exists(): rval = os.EX_OK - elif mylink.unmerge(ldpath_mtimes=self.prev_mtimes) == os.EX_OK: + elif mylink.unmerge(ldpath_mtimes=prev_mtimes) == os.EX_OK: mylink.lockdb() try: mylink.delete() @@ -234,11 +265,11 @@ class MergeProcess(ForkProcess): rval = os.EX_OK else: rval = mylink.merge( - self.pkgloc, - self.infloc, - myebuild=self.myebuild, - mydbapi=self.mydbapi, - prev_mtimes=self.prev_mtimes, + pkgloc, + infloc, + myebuild=myebuild, + mydbapi=mydbapi, + prev_mtimes=prev_mtimes, counter=counter, ) return rval