diff --git a/src/trio/_core/_tests/test_guest_mode.py b/src/trio/_core/_tests/test_guest_mode.py index 56f25fd21..78a1a47bc 100644 --- a/src/trio/_core/_tests/test_guest_mode.py +++ b/src/trio/_core/_tests/test_guest_mode.py @@ -440,8 +440,9 @@ def aiotrio_run( pass_not_threadsafe: bool = True, **start_guest_run_kwargs: Any, ) -> T: + loop = asyncio.get_running_loop() + async def aio_main() -> T: - loop = asyncio.get_running_loop() trio_done_fut: asyncio.Future[Outcome[T]] = loop.create_future() def trio_done_callback(main_outcome: Outcome[T]) -> None: @@ -460,7 +461,12 @@ def trio_done_callback(main_outcome: Outcome[T]) -> None: return (await trio_done_fut).unwrap() - return asyncio.run(aio_main()) + try: + # can't use asyncio.run because that fails on Windows (3.8, x64, with + # Komodia LSP) + return loop.run_until_complete(aio_main()) + finally: + loop.close() def test_guest_mode_on_asyncio() -> None: