Skip to content

Commit b702da2

Browse files
committed
Fix a re-entrancy deadlock.
1 parent 6f19384 commit b702da2

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Python/pystate.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,19 +2789,17 @@ PyGILState_Ensure(void)
27892789
assert(tcur->gilstate_counter == 1);
27902790
tcur->gilstate_counter = 0;
27912791
has_gil = 0; /* new thread state is never current */
2792+
PyInterpreterRef_Close(ref);
27922793
}
27932794
else {
27942795
has_gil = holds_gil(tcur);
27952796
}
27962797

27972798
if (!has_gil) {
2799+
// XXX Do we need to protect this against finalization?
27982800
PyEval_RestoreThread(tcur);
27992801
}
28002802

2801-
if (tcur == NULL) {
2802-
PyInterpreterRef_Close(ref);
2803-
}
2804-
28052803
/* Update our counter in the thread-state - no need for locks:
28062804
- tcur will remain valid as we hold the GIL.
28072805
- the counter is safe as we are the only thread "allowed"

0 commit comments

Comments
 (0)