diff options
author | 2023-10-23 18:43:03 -0700 | |
---|---|---|
committer | 2023-10-23 19:09:53 -0700 | |
commit | 986b59bd7443b23146217f581e7b3b82a5d4912f (patch) | |
tree | d6048f7c44e00046d4e964f5a928b05e1a7a11cd /bin | |
parent | StaticFileSet: Fix os.walk for utf8_mode (diff) | |
download | portage-986b59bd7443b23146217f581e7b3b82a5d4912f.tar.gz portage-986b59bd7443b23146217f581e7b3b82a5d4912f.tar.bz2 portage-986b59bd7443b23146217f581e7b3b82a5d4912f.zip |
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 <zmedico@gentoo.org>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/emaint | 27 |
1 files changed, 16 insertions, 11 deletions
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 |