From ab8081fab66eafcb35021f45ffae0648b658733e Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 25 Dec 2022 01:45:01 -0500 Subject: mtest: clean up asyncio event loop instantiation Fix a TODO comment about moving to asyncio.run, now that we use sufficiently new python to do it. Note that we create an event loop for Windows using the new python defaults, but in a completely different part of the code from where we need to use it. Since asyncio.run creates the loop on its own, we need to set the default policy instead -- which we probably should have done all along. --- mesonbuild/mtest.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index b398705..5c584e0 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -1925,9 +1925,12 @@ class TestHarness: def run_tests(self, runners: T.List[SingleTestRunner]) -> None: try: self.open_logfiles() - # Replace with asyncio.run once we can require Python 3.7 - loop = asyncio.get_event_loop() - loop.run_until_complete(self._run_tests(runners)) + + # TODO: this is the default for python 3.8 + if sys.platform == 'win32': + asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy()) + + asyncio.run(self._run_tests(runners)) finally: self.close_logfiles() @@ -2090,10 +2093,6 @@ def run(options: argparse.Namespace) -> int: if options.wrapper: check_bin = options.wrapper[0] - if sys.platform == 'win32': - loop = asyncio.ProactorEventLoop() - asyncio.set_event_loop(loop) - if check_bin is not None: exe = ExternalProgram(check_bin, silent=True) if not exe.found(): -- cgit v1.1