commit: cfd767cd35f5affd3b61b665b0f8814fe2de24c4 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Wed Aug 14 05:30:42 2024 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Wed Aug 14 15:22:05 2024 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=cfd767cd
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 <zmedico <AT> gentoo.org> lib/portage/process.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/portage/process.py b/lib/portage/process.py index 38adebda66..e6f6feb357 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:
