summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-07-06 15:18:21 (GMT)
committerGitHub <noreply@github.com>2022-07-06 15:18:21 (GMT)
commit14fea6b4d25658bc00adbb97dd40ea3d3e6843ad (patch)
tree7b5f24a0085968ed234761e74cc96c9dc2dd99b0 /Lib/asyncio
parente925241d95d8095adf67f492042f97254ff82ec1 (diff)
downloadcpython-14fea6b4d25658bc00adbb97dd40ea3d3e6843ad.zip
cpython-14fea6b4d25658bc00adbb97dd40ea3d3e6843ad.tar.gz
cpython-14fea6b4d25658bc00adbb97dd40ea3d3e6843ad.tar.bz2
GH-93896: AAlways set event loop in asyncio.run and IsolatedAsyncioTestCase (#94593)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/runners.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/asyncio/runners.py b/Lib/asyncio/runners.py
index f524c3b..7489a50 100644
--- a/Lib/asyncio/runners.py
+++ b/Lib/asyncio/runners.py
@@ -52,6 +52,7 @@ class Runner:
self._loop = None
self._context = None
self._interrupt_count = 0
+ self._set_event_loop = False
def __enter__(self):
self._lazy_init()
@@ -70,6 +71,8 @@ class Runner:
loop.run_until_complete(loop.shutdown_asyncgens())
loop.run_until_complete(loop.shutdown_default_executor())
finally:
+ if self._set_event_loop:
+ events.set_event_loop(None)
loop.close()
self._loop = None
self._state = _State.CLOSED
@@ -111,6 +114,8 @@ class Runner:
self._interrupt_count = 0
try:
+ if self._set_event_loop:
+ events.set_event_loop(self._loop)
return self._loop.run_until_complete(task)
except exceptions.CancelledError:
if self._interrupt_count > 0 and task.uncancel() == 0:
@@ -130,6 +135,7 @@ class Runner:
return
if self._loop_factory is None:
self._loop = events.new_event_loop()
+ self._set_event_loop = True
else:
self._loop = self._loop_factory()
if self._debug is not None: