public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: lib/portage/util/, lib/portage/, lib/portage/tests/locks/
@ 2024-01-29  8:51 Zac Medico
  0 siblings, 0 replies; only message in thread
From: Zac Medico @ 2024-01-29  8:51 UTC (permalink / raw
  To: gentoo-commits

commit:     d4c495c6bd543d07f3c5d6e72145e177999edaab
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 28 23:44:23 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jan 29 04:08:42 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=d4c495c6

Rely on os.register_at_fork for _ForkWatcher hook invocation

Because os.register_at_fork is used instead of
multiprocessing.util.register_after_fork since commit
cc7c40199850acb3d36f0a6452987231d592c360, we can rely on the
_ForkWatcher hook being automatically invoked after os.fork().

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/process.py                        | 10 +++-------
 lib/portage/tests/locks/test_lock_nonblock.py |  3 +--
 lib/portage/util/locale.py                    |  3 +--
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/lib/portage/process.py b/lib/portage/process.py
index 28f977a046..0d58adecad 100644
--- a/lib/portage/process.py
+++ b/lib/portage/process.py
@@ -1,5 +1,5 @@
 # portage.py -- core Portage functionality
-# Copyright 1998-2023 Gentoo Authors
+# Copyright 1998-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 
@@ -456,7 +456,6 @@ def spawn(
         pid = os.fork()
 
         if pid == 0:
-            portage._ForkWatcher.hook(portage._ForkWatcher)
             try:
                 _exec(
                     binary,
@@ -504,8 +503,8 @@ def spawn(
                 sys.stderr.flush()
 
     finally:
-        # Don't used portage.getpid() here, due to a race with the above
-        # portage._ForkWatcher cache update.
+        # Don't used portage.getpid() here, in case there is a race
+        # with getpid cache invalidation via _ForkWatcher hook.
         if pid == 0 or (pid is None and _os.getpid() != parent_pid):
             # Call os._exit() from a finally block in order
             # to suppress any finally blocks from earlier
@@ -775,9 +774,6 @@ def _exec(
                         if unshare_pid:
                             main_child_pid = os.fork()
                             if main_child_pid == 0:
-                                # The portage.getpid() cache may need to be updated here,
-                                # in case the pre_exec function invokes portage APIs.
-                                portage._ForkWatcher.hook(portage._ForkWatcher)
                                 # pid namespace requires us to become init
                                 binary, myargs = (
                                     portage._python_interpreter,

diff --git a/lib/portage/tests/locks/test_lock_nonblock.py b/lib/portage/tests/locks/test_lock_nonblock.py
index e3f9b4d023..9bb91b428e 100644
--- a/lib/portage/tests/locks/test_lock_nonblock.py
+++ b/lib/portage/tests/locks/test_lock_nonblock.py
@@ -1,4 +1,4 @@
-# Copyright 2011-2020 Gentoo Authors
+# Copyright 2011-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import tempfile
@@ -19,7 +19,6 @@ class LockNonblockTestCase(TestCase):
             lock1 = portage.locks.lockfile(path)
             pid = os.fork()
             if pid == 0:
-                portage._ForkWatcher.hook(portage._ForkWatcher)
                 portage.locks._close_fds()
                 # Disable close_fds since we don't exec
                 # (see _setup_pipes docstring).

diff --git a/lib/portage/util/locale.py b/lib/portage/util/locale.py
index 0d0c120157..a620dbd544 100644
--- a/lib/portage/util/locale.py
+++ b/lib/portage/util/locale.py
@@ -1,4 +1,4 @@
-# Copyright 2015-2020 Gentoo Authors
+# Copyright 2015-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 """
@@ -118,7 +118,6 @@ def check_locale(silent=False, env=None):
 
     pid = os.fork()
     if pid == 0:
-        portage._ForkWatcher.hook(portage._ForkWatcher)
         try:
             if env is not None:
                 try:


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-29  8:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-29  8:51 [gentoo-commits] proj/portage:master commit in: lib/portage/util/, lib/portage/, lib/portage/tests/locks/ Zac Medico

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox