From 986b59bd7443b23146217f581e7b3b82a5d4912f Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 23 Oct 2023 18:43:03 -0700 Subject: bin/emaint: 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 --- bin/emaint | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'bin') diff --git a/bin/emaint b/bin/emaint index a1b726b18..da925e1da 100755 --- a/bin/emaint +++ b/bin/emaint @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright 2005-2020 Gentoo Authors +# Copyright 2005-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 """System health checks and maintenance utilities. @@ -53,16 +53,21 @@ try: from portage.emaint.main import emaint_main from portage.util._eventloop.global_event_loop import global_event_loop - try: - emaint_main(sys.argv[1:]) - except OSError as e: - if e.errno == errno.EACCES: - print("\nemaint: Need superuser access") - sys.exit(1) - else: - raise - finally: - global_event_loop().close() + if __name__ == "__main__": + try: + emaint_main(sys.argv[1:]) + except OSError as e: + if e.errno == errno.EACCES: + print("\nemaint: Need superuser access") + sys.exit(1) + else: + raise + finally: + # 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 -- cgit v1.2.3-65-gdbad