diff options
author | Yury Selivanov <yselivanov@sprymix.com> | 2016-03-02 16:30:46 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@sprymix.com> | 2016-03-02 16:30:46 (GMT) |
commit | c724bae51cd0580cd493f319f3b14c2e1a28f3b6 (patch) | |
tree | afe43c1777b5b40b5d352ed0cd232ec1c88b971c /Python/ceval.c | |
parent | e076ffb068ce4e76a7103451c3bef79c2610f791 (diff) | |
download | cpython-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/ceval.c')
-rw-r--r-- | Python/ceval.c | 15 |
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) { |