From 41782e497092a27efbae20208ce7d48c657e74cb Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Wed, 16 Nov 2016 18:16:17 -0500 Subject: Issue #28721: Fix asynchronous generators aclose() and athrow() --- Objects/genobject.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Objects/genobject.c') diff --git a/Objects/genobject.c b/Objects/genobject.c index ddf72ccf69..558f809b02 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1931,9 +1931,17 @@ yield_close: return NULL; check_error: - if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) - || PyErr_ExceptionMatches(PyExc_GeneratorExit) - ) { + if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration)) { + o->agt_state = AWAITABLE_STATE_CLOSED; + if (o->agt_args == NULL) { + /* when aclose() is called we don't want to propagate + StopAsyncIteration; just raise StopIteration, signalling + that 'aclose()' is done. */ + PyErr_Clear(); + PyErr_SetNone(PyExc_StopIteration); + } + } + else if (PyErr_ExceptionMatches(PyExc_GeneratorExit)) { o->agt_state = AWAITABLE_STATE_CLOSED; PyErr_Clear(); /* ignore these errors */ PyErr_SetNone(PyExc_StopIteration); -- cgit v1.2.1