From 52698c7ad9eae9feb35839fde17a7d1da8036a9b Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Thu, 7 Jun 2018 20:31:26 -0400 Subject: bpo-33786: Fix asynchronous generators to handle GeneratorExit in athrow() (GH-7467) --- Objects/genobject.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'Objects/genobject.c') diff --git a/Objects/genobject.c b/Objects/genobject.c index 9f593382f5..e55cfd21c6 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1876,21 +1876,20 @@ yield_close: return NULL; check_error: - if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration)) { + if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) || + PyErr_ExceptionMatches(PyExc_GeneratorExit)) + { 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. */ + StopAsyncIteration or GeneratorExit; just raise + StopIteration, signalling that this 'aclose()' await + 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); - } return NULL; } -- cgit v1.2.1