diff options
author | Zac Medico <zmedico@gentoo.org> | 2024-08-08 07:58:31 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2024-08-08 07:58:31 -0700 |
commit | d6710ee0cdab2a212ff70503f9699f1be4660bb4 (patch) | |
tree | 392712bc816757b10d6ef8c3451402ba45f7ba71 /README.md | |
parent | doebuild.spawn: Skip socks5 proxy for "depend" phase (diff) | |
download | portage-d6710ee0cdab2a212ff70503f9699f1be4660bb4.tar.gz portage-d6710ee0cdab2a212ff70503f9699f1be4660bb4.tar.bz2 portage-d6710ee0cdab2a212ff70503f9699f1be4660bb4.zip |
run_exitfuncs: Support loop close via hook
Handle the case where the loop has not been explicitly closed before
exit. In this case, run_exitfuncs previously tried to call coroutine
functions as though they were normal functions, which obvously would
not behave correctly.
Solve this problem by storing the coroutine functions in a separate
_coroutine_exithandlers list that belongs exclusively to the
run_coroutine_exitfuncs function, so that it is safe to close the
loop and call run_coroutine_exitfuncs from inside a run_exitfuncs
hook. A _thread_weakrefs_atexit hook already exists that will close
weakly referenced loops. The _thread_weakrefs_atexit hook is now
fixed to release its lock when it closes a loop, since the same
lock may need to be re-acquired when run_coroutine_exitfuncs runs.
The included test case demonstrates that run_exitfuncs will run
via an atexit hook and correctly terminate the socks5 proxy in a
standalone program using the portage API (like eclean).
Due to a deadlock that will occur if an _exit_function atexit hook
from the multiprocessing module executes before run_exitfuncs, a
portage.process._atexit_register_run_exitfuncs() function needs to
be called in order to re-order the hooks after the first process
has been started via the multiprocessing module. The natural place
to call this is in the ForkProcess class, using a global variable
to trigger the call just once.
Fixes: c3ebdbb42e72 ("elog/mod_custom: Spawn processes in background")
Bug: https://bugs.gentoo.org/937384
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'README.md')
0 files changed, 0 insertions, 0 deletions