mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-35409: Ignore GeneratorExit in async_gen_athrow_throw (GH-14755)
Ignore `GeneratorExit` exceptions when throwing an exception into the `aclose` coroutine of an asynchronous generator. https://bugs.python.org/issue35409
This commit is contained in:
parent
f25875af42
commit
8e0de2a480
3 changed files with 40 additions and 0 deletions
|
@ -1932,6 +1932,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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue