fix dangling thread state issue (#5870)

* fix dangling thread state issue

* formatting rules

* use tstate .set(nullptr) to pass clang-tidy check

* fix spelling mistake

* improve comments for maintainability
This commit is contained in:
daltairwalter
2025-10-16 10:40:50 -05:00
committed by GitHub
parent 1e5bc66e38
commit 15943963b3
2 changed files with 2 additions and 2 deletions

View File

@@ -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);

View File

@@ -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_;
}