summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2016-03-02 16:30:46 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2016-03-02 16:30:46 (GMT)
commitc724bae51cd0580cd493f319f3b14c2e1a28f3b6 (patch)
treeafe43c1777b5b40b5d352ed0cd232ec1c88b971c /Python
parente076ffb068ce4e76a7103451c3bef79c2610f791 (diff)
downloadcpython-c724bae51cd0580cd493f319f3b14c2e1a28f3b6.zip
cpython-c724bae51cd0580cd493f319f3b14c2e1a28f3b6.tar.gz
cpython-c724bae51cd0580cd493f319f3b14c2e1a28f3b6.tar.bz2
coroutines: Error when awaiting on coroutine that's being awaited
Issue #25888
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index aee0e6b..f9ecad4 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2021,6 +2021,21 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
Py_DECREF(iterable);
+ if (iter != NULL && PyCoro_CheckExact(iter)) {
+ PyObject *yf = _PyGen_yf((PyGenObject*)iter);
+ if (yf != NULL) {
+ /* `iter` is a coroutine object that is being
+ awaited, `yf` is a pointer to the current awaitable
+ being awaited on. */
+ Py_DECREF(yf);
+ Py_CLEAR(iter);
+ PyErr_SetString(
+ PyExc_RuntimeError,
+ "coroutine is being awaited already");
+ /* The code below jumps to `error` if `iter` is NULL. */
+ }
+ }
+
SET_TOP(iter); /* Even if it's NULL */
if (iter == NULL) {