diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2020-01-04 09:10:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-04 09:10:14 (GMT) |
commit | 3a5de511596f17575de082dcb8d43d63b2bd2da9 (patch) | |
tree | 4c7b6255c00d9b565082997015695e6f0909e202 /Lib/asyncio | |
parent | e02ab59fdffa0bb841182c30ef1355c89578d945 (diff) | |
download | cpython-3a5de511596f17575de082dcb8d43d63b2bd2da9.zip cpython-3a5de511596f17575de082dcb8d43d63b2bd2da9.tar.gz cpython-3a5de511596f17575de082dcb8d43d63b2bd2da9.tar.bz2 |
Fix #39191: Don't spawn a task before failing (#17796)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/base_events.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index adcdec1..e53ca73 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -573,14 +573,17 @@ class BaseEventLoop(events.AbstractEventLoop): except Exception as ex: self.call_soon_threadsafe(future.set_exception, ex) - def run_forever(self): - """Run until stop() is called.""" - self._check_closed() + def _check_runnung(self): if self.is_running(): raise RuntimeError('This event loop is already running') if events._get_running_loop() is not None: raise RuntimeError( 'Cannot run the event loop while another loop is running') + + def run_forever(self): + """Run until stop() is called.""" + self._check_closed() + self._check_runnung() self._set_coroutine_origin_tracking(self._debug) self._thread_id = threading.get_ident() @@ -612,6 +615,7 @@ class BaseEventLoop(events.AbstractEventLoop): Return the Future's result, or raise its exception. """ self._check_closed() + self._check_runnung() new_task = not futures.isfuture(future) future = tasks.ensure_future(future, loop=self) |