commit: 4ec75ab8717787d5f24f35685cfc138f5a77901f Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Tue Oct 24 01:05:57 2023 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Tue Oct 24 02:14:29 2023 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=4ec75ab8
bin/ebuild: Use __main__ for spawn compat If the event loop is closed outside of __main__ then it closes the event loop in child processes for the multiprocessing spawn start method. Bug: https://bugs.gentoo.org/916142 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> bin/ebuild | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/bin/ebuild b/bin/ebuild index 2fa4e7974a..09457b2940 100755 --- a/bin/ebuild +++ b/bin/ebuild @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright 1999-2022 Gentoo Authors +# Copyright 1999-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import os @@ -17,8 +17,7 @@ class SignalInterrupt(KeyboardInterrupt): self.signum = signum -try: - +def main(): def signal_interrupt(signum, _frame): raise SignalInterrupt(signum) @@ -433,10 +432,18 @@ try: global_event_loop().close() sys.exit(a) + # Only close the event loop for __main__, + # since outside of __main__ it would close the + # event loop for child processes when using + # the multiprocessing spawn start method. global_event_loop().close() -except KeyboardInterrupt as e: - # Prevent traceback on ^C - signum = getattr(e, "signum", signal.SIGINT) - signal.signal(signum, signal.SIG_DFL) - raise_signal(signum) + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt as e: + # Prevent traceback on ^C + signum = getattr(e, "signum", signal.SIGINT) + signal.signal(signum, signal.SIG_DFL) + raise_signal(signum)
