GH-95899: fix asyncio.Runner to call set_event_loop only once (GH-95900) (#96003)

(cherry picked from commit 914f6367a0)

Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2022-08-15 15:01:23 -07:00 committed by GitHub
parent 3fa97b8589
commit 8bd7a0b581
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View file

@ -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: