From cfd767cd35f5affd3b61b665b0f8814fe2de24c4 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 13 Aug 2024 22:30:42 -0700 Subject: run_exitfuncs: Drop hooks inherited via fork Drop hooks inherited via fork because they can trigger redundant actions as shown in bug 937891. Note that atexit hooks only work after fork since issue 83856 was fixed in Python 3.13. Bug: https://bugs.gentoo.org/937891 Signed-off-by: Zac Medico --- lib/portage/process.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/portage/process.py b/lib/portage/process.py index 38adebda6..e6f6feb35 100644 --- a/lib/portage/process.py +++ b/lib/portage/process.py @@ -208,7 +208,7 @@ def atexit_register(func, *args, **kargs): # which is associated with the current thread. global_event_loop()._coroutine_exithandlers.append((func, args, kargs)) else: - _exithandlers.append((func, args, kargs)) + _exithandlers.append((func, args, kargs, portage.getpid())) def run_exitfuncs(): @@ -222,7 +222,12 @@ def run_exitfuncs(): # original function is in the output to stderr. exc_info = None while _exithandlers: - func, targs, kargs = _exithandlers.pop() + func, targs, kargs, pid = _exithandlers.pop() + if pid != portage.getpid(): + # Drop hooks inherited via fork because they can trigger redundant + # actions as shown in bug 937891. Note that atexit hooks only work + # after fork since issue 83856 was fixed in Python 3.13. + continue try: func(*targs, **kargs) except SystemExit: -- cgit v1.2.3-65-gdbad