diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 4f8de120f..003ee6e15 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -286,8 +286,8 @@ struct internals { internals() : static_property_type(make_static_property_type()), default_metaclass(make_default_metaclass()) { + tstate.set(nullptr); // See PR #5870 PyThreadState *cur_tstate = PyThreadState_Get(); - tstate = cur_tstate; istate = cur_tstate->interp; registered_exception_translators.push_front(&translate_exception); diff --git a/include/pybind11/subinterpreter.h b/include/pybind11/subinterpreter.h index 4b208ed9b..5d2f0a839 100644 --- a/include/pybind11/subinterpreter.h +++ b/include/pybind11/subinterpreter.h @@ -271,7 +271,7 @@ inline subinterpreter_scoped_activate::subinterpreter_scoped_activate(subinterpr // make the interpreter active and acquire the GIL old_tstate_ = PyThreadState_Swap(tstate_); - // save this in internals for scoped_gil calls + // save this in internals for scoped_gil calls (see also: PR #5870) detail::get_internals().tstate = tstate_; }