Skip to content

Commit d2863f5

Browse files
committed
Fix #5827
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
1 parent 074daf0 commit d2863f5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

include/pybind11/gil.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ class gil_scoped_acquire {
120120
pybind11_fail("scoped_acquire::dec_ref(): internal error!");
121121
}
122122
# endif
123+
// Make sure that PyThreadState_Clear is not recursively called by finalizers.
124+
// See issue #5827
125+
++tstate->gilstate_counter;
123126
PyThreadState_Clear(tstate);
127+
--tstate->gilstate_counter;
124128
if (active) {
125129
PyThreadState_DeleteCurrent();
126130
}

0 commit comments

Comments
 (0)