Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3a5de51

Browse files
authored
Fix #39191: Don't spawn a task before failing (#17796)
1 parent e02ab59 commit 3a5de51

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Lib/asyncio/base_events.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,17 @@ def _do_shutdown(self, future):
573573
except Exception as ex:
574574
self.call_soon_threadsafe(future.set_exception, ex)
575575

576-
def run_forever(self):
577-
"""Run until stop() is called."""
578-
self._check_closed()
576+
def _check_runnung(self):
579577
if self.is_running():
580578
raise RuntimeError('This event loop is already running')
581579
if events._get_running_loop() is not None:
582580
raise RuntimeError(
583581
'Cannot run the event loop while another loop is running')
582+
583+
def run_forever(self):
584+
"""Run until stop() is called."""
585+
self._check_closed()
586+
self._check_runnung()
584587
self._set_coroutine_origin_tracking(self._debug)
585588
self._thread_id = threading.get_ident()
586589

@@ -612,6 +615,7 @@ def run_until_complete(self, future):
612615
Return the Future's result, or raise its exception.
613616
"""
614617
self._check_closed()
618+
self._check_runnung()
615619

616620
new_task = not futures.isfuture(future)
617621
future = tasks.ensure_future(future, loop=self)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Perform a check for running loop before starting a new task in
2+
``loop.run_until_complete()`` to fail fast; it prevents the side effect of
3+
new task spawning before exception raising.

0 commit comments

Comments
 (0)