summaryrefslogtreecommitdiff
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2016-03-02 11:30:46 -0500
committerYury Selivanov <yselivanov@sprymix.com>2016-03-02 11:30:46 -0500
commitc724bae51cd0580cd493f319f3b14c2e1a28f3b6 (patch)
treeafe43c1777b5b40b5d352ed0cd232ec1c88b971c /Python/ceval.c
parente076ffb068ce4e76a7103451c3bef79c2610f791 (diff)
downloadcpython-git-c724bae51cd0580cd493f319f3b14c2e1a28f3b6.tar.gz
coroutines: Error when awaiting on coroutine that's being awaited
Issue #25888
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index aee0e6bc85..f9ecad46cf 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) {