mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
GH-117881: fix athrow().throw()/asend().throw() concurrent access (GH-117882)
This commit is contained in:
parent
2520eed0a5
commit
fc7e1aa3c0
3 changed files with 235 additions and 2 deletions
|
@ -1774,6 +1774,7 @@ async_gen_asend_send(PyAsyncGenASend *o, PyObject *arg)
|
|||
|
||||
if (o->ags_state == AWAITABLE_STATE_INIT) {
|
||||
if (o->ags_gen->ag_running_async) {
|
||||
o->ags_state = AWAITABLE_STATE_CLOSED;
|
||||
PyErr_SetString(
|
||||
PyExc_RuntimeError,
|
||||
"anext(): asynchronous generator is already running");
|
||||
|
@ -1817,10 +1818,24 @@ async_gen_asend_throw(PyAsyncGenASend *o, PyObject *const *args, Py_ssize_t narg
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (o->ags_state == AWAITABLE_STATE_INIT) {
|
||||
if (o->ags_gen->ag_running_async) {
|
||||
o->ags_state = AWAITABLE_STATE_CLOSED;
|
||||
PyErr_SetString(
|
||||
PyExc_RuntimeError,
|
||||
"anext(): asynchronous generator is already running");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
o->ags_state = AWAITABLE_STATE_ITER;
|
||||
o->ags_gen->ag_running_async = 1;
|
||||
}
|
||||
|
||||
result = gen_throw((PyGenObject*)o->ags_gen, args, nargs);
|
||||
result = async_gen_unwrap_value(o->ags_gen, result);
|
||||
|
||||
if (result == NULL) {
|
||||
o->ags_gen->ag_running_async = 0;
|
||||
o->ags_state = AWAITABLE_STATE_CLOSED;
|
||||
}
|
||||
|
||||
|
@ -2209,10 +2224,31 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *const *args, Py_ssize_t na
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (o->agt_state == AWAITABLE_STATE_INIT) {
|
||||
if (o->agt_gen->ag_running_async) {
|
||||
o->agt_state = AWAITABLE_STATE_CLOSED;
|
||||
if (o->agt_args == NULL) {
|
||||
PyErr_SetString(
|
||||
PyExc_RuntimeError,
|
||||
"aclose(): asynchronous generator is already running");
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(
|
||||
PyExc_RuntimeError,
|
||||
"athrow(): asynchronous generator is already running");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
o->agt_state = AWAITABLE_STATE_ITER;
|
||||
o->agt_gen->ag_running_async = 1;
|
||||
}
|
||||
|
||||
retval = gen_throw((PyGenObject*)o->agt_gen, args, nargs);
|
||||
if (o->agt_args) {
|
||||
retval = async_gen_unwrap_value(o->agt_gen, retval);
|
||||
if (retval == NULL) {
|
||||
o->agt_gen->ag_running_async = 0;
|
||||
o->agt_state = AWAITABLE_STATE_CLOSED;
|
||||
}
|
||||
return retval;
|
||||
|
@ -2226,6 +2262,7 @@ async_gen_athrow_throw(PyAsyncGenAThrow *o, PyObject *const *args, Py_ssize_t na
|
|||
return NULL;
|
||||
}
|
||||
if (retval == NULL) {
|
||||
o->agt_gen->ag_running_async = 0;
|
||||
o->agt_state = AWAITABLE_STATE_CLOSED;
|
||||
}
|
||||
if (PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue