Skip to content

Commit 770ce09

Browse files
committed
Don't try and re-lock the generator to clear it.
1 parent 173ba3b commit 770ce09

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Python/ceval.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,12 @@ clear_gen_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
17411741
{
17421742
assert(frame->owner == FRAME_OWNED_BY_GENERATOR);
17431743
PyGenObject *gen = _PyGen_GetGeneratorFromFrame(frame);
1744-
Py_BEGIN_CRITICAL_SECTION(gen);
1744+
/* It's safe to assume that the generator is locked, because this
1745+
* was eventually called by something that locked it already.
1746+
*
1747+
* In fact, trying to lock the generator here ends up breaking
1748+
* the critical section API. */
1749+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(gen);
17451750
gen->gi_frame_state = FRAME_CLEARED;
17461751
assert(tstate->exc_info == &gen->gi_exc_state);
17471752
tstate->exc_info = gen->gi_exc_state.previous_item;
@@ -1752,7 +1757,6 @@ clear_gen_frame(PyThreadState *tstate, _PyInterpreterFrame * frame)
17521757
_PyErr_ClearExcState(&gen->gi_exc_state);
17531758
tstate->c_recursion_remaining++;
17541759
frame->previous = NULL;
1755-
Py_END_CRITICAL_SECTION();
17561760
}
17571761

17581762
void

0 commit comments

Comments
 (0)