From 9bfa7fb9068d3aa39504cccc5fcc583e76600589 Mon Sep 17 00:00:00 2001 From: Matthew Pearson Date: Mon, 4 Sep 2023 23:26:26 -0700 Subject: [PATCH] Fix "Event loop is closed" error on windows Switched from asyncio.run() to asyncio.get_event_loop.run_until_complete() --- revup/__main__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/revup/__main__.py b/revup/__main__.py index 8a9be63..706dae6 100644 --- a/revup/__main__.py +++ b/revup/__main__.py @@ -14,8 +14,12 @@ def _main() -> None: try: - # Exit code of 1 is reserved for exception-based exits - sys.exit(asyncio.run(main())) + # Exit code of 1 is reserved for exception-based exits. + # Note: on Windows, asyncio.run() doesn't work properly due to this issue: + # https://stackoverflow.com/questions/63860576/asyncio-event-loop-is-closed-when-using-asyncio-run + # Since revup makes use of subprocess, we can't use WindowsSelectorEventLoopPolicy. + # Instead, we can manually create the event loop and prevent the RuntimeError on shutdown. + sys.exit(asyncio.get_event_loop().run_until_complete(main())) except RevupUsageException as e: logging.error(str(e)) sys.exit(2)