gh-143939: Fix assignment to `_PyThreadStateImpl.generator_return_kin… · python/cpython@43bb630 · GitHub
Skip to content

Commit 43bb630

Browse files
authored
gh-143939: Fix assignment to _PyThreadStateImpl.generator_return_kind (gh-143951)
The assignment to generator_return_kind has to be after any potentially escaping calls to ensure that it's not overwritten.
1 parent a126893 commit 43bb630

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

Lib/test/test_coroutines.py

Lines changed: 14 additions & 0 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix erroneous "cannot reuse already awaited coroutine" error that could
2+
occur when a generator was run during the process of clearing a coroutine's
3+
frame.

Objects/genobject.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult, int exc)
280280

281281
if (return_kind == GENERATOR_YIELD) {
282282
assert(result != NULL && !_PyErr_Occurred(tstate));
283+
#ifndef Py_GIL_DISABLED
284+
assert(FRAME_STATE_SUSPENDED(gen->gi_frame_state));
285+
#endif
283286
*presult = result;
284287
return PYGEN_NEXT;
285288
}

Python/ceval.c

Lines changed: 3 additions & 1 deletion

0 commit comments

Comments
 (0)