From f6a61e451dfcfa53aa69066ccc58bfca77eafe4b Mon Sep 17 00:00:00 2001 From: Will Smith Date: Mon, 24 Jul 2023 17:17:50 -0700 Subject: [PATCH] Fixed python warning: DeprecationWarning: There is no current event loop (#89404) * Fixed python warning: DeprecationWarning: There is no current event loop * Update superpmi.py --- src/coreclr/scripts/superpmi.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/coreclr/scripts/superpmi.py b/src/coreclr/scripts/superpmi.py index d5a12f1..78d7882 100644 --- a/src/coreclr/scripts/superpmi.py +++ b/src/coreclr/scripts/superpmi.py @@ -539,10 +539,6 @@ class AsyncSubprocessHelper: self.verbose = verbose self.subproc_count_queue = None - if 'win32' in sys.platform: - # Windows specific event-loop policy & cmd - asyncio.set_event_loop(asyncio.ProactorEventLoop()) - async def __get_item__(self, item, index, size, async_callback, *extra_args): """ Wrapper to the async callback which will schedule based on the queue """ @@ -600,7 +596,18 @@ class AsyncSubprocessHelper: """ reset_env = os.environ.copy() - loop = asyncio.get_event_loop() + + try: + loop = asyncio.get_running_loop() + except RuntimeError: + if 'win32' in sys.platform: + # Windows specific event-loop policy & cmd + loop = asyncio.ProactorEventLoop() + else: + loop = asyncio.new_event_loop() + + asyncio.set_event_loop(loop) + loop.run_until_complete(self.__run_to_completion__(async_callback, *extra_args)) os.environ.clear() os.environ.update(reset_env) -- 2.7.4