summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/runners.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-08-15 22:01:23 (GMT)
committerGitHub <noreply@github.com>2022-08-15 22:01:23 (GMT)
commit8bd7a0b5810529cd3ed378de42a74e9301856f12 (patch)
tree8694a7367a7b68d1f702ef38ab818bac2bd2d5c0 /Lib/asyncio/runners.py
parent3fa97b8589c551e70ec935e7f39d56c3c5d5ed7e (diff)
downloadcpython-8bd7a0b5810529cd3ed378de42a74e9301856f12.zip
cpython-8bd7a0b5810529cd3ed378de42a74e9301856f12.tar.gz
cpython-8bd7a0b5810529cd3ed378de42a74e9301856f12.tar.bz2
GH-95899: fix asyncio.Runner to call set_event_loop only once (GH-95900) (#96003)
(cherry picked from commit 914f6367a0d015986dafa7a9d542e24192753b6b) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib/asyncio/runners.py')
-rw-r--r--Lib/asyncio/runners.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/asyncio/runners.py b/Lib/asyncio/runners.py
index a19a7f9..b3e0c44 100644
--- a/Lib/asyncio/runners.py
+++ b/Lib/asyncio/runners.py
@@ -115,8 +115,6 @@ 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:
@@ -137,7 +135,11 @@ class Runner:
return
if self._loop_factory is None:
self._loop = events.new_event_loop()
- self._set_event_loop = True
+ if not self._set_event_loop:
+ # Call set_event_loop only once to avoid calling
+ # attach_loop multiple times on child watchers
+ events.set_event_loop(self._loop)
+ self._set_event_loop = True
else:
self._loop = self._loop_factory()
if self._debug is not None: