summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/base_events.py
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2020-01-04 09:49:32 (GMT)
committerGitHub <noreply@github.com>2020-01-04 09:49:32 (GMT)
commit9c145e19fba53369da5cd23a1e71de489836f827 (patch)
treea8ff8a6cc7c4e565ecac65589f46207018a969aa /Lib/asyncio/base_events.py
parent83638fe0a7b90189677e0d4b40426f50a3a89a2c (diff)
downloadcpython-9c145e19fba53369da5cd23a1e71de489836f827.zip
cpython-9c145e19fba53369da5cd23a1e71de489836f827.tar.gz
cpython-9c145e19fba53369da5cd23a1e71de489836f827.tar.bz2
[3.7] bpo-39191: Don't spawn a task before failing (GH-17796) (#17821)
(cherry picked from commit 3a5de511596f17575de082dcb8d43d63b2bd2da9) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Lib/asyncio/base_events.py')
-rw-r--r--Lib/asyncio/base_events.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index fdd80bc..f723356 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -518,14 +518,17 @@ class BaseEventLoop(events.AbstractEventLoop):
'asyncgen': agen
})
- 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()
@@ -557,6 +560,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)