diff --git a/Objects/genobject.c b/Objects/genobject.c index e2def38af5..14c0f24d9d 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1923,6 +1923,17 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *args) PyErr_SetString(PyExc_RuntimeError, ASYNC_GEN_IGNORED_EXIT_MSG); return NULL; } + if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) || + PyErr_ExceptionMatches(PyExc_GeneratorExit)) + { + /* when aclose() is called we don't want to propagate + StopAsyncIteration or GeneratorExit; just raise + StopIteration, signalling that this 'aclose()' await + is done. + */ + PyErr_Clear(); + PyErr_SetNone(PyExc_StopIteration); + } return retval; } }