Skip to content

Commit 4ef8b0c

Browse files
committed
Disable thread local cache for internals_pp_manager
1 parent 5c7e1d7 commit 4ef8b0c

2 files changed

Lines changed: 2 additions & 42 deletions

File tree

include/pybind11/detail/internals.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -648,28 +648,8 @@ class internals_pp_manager {
648648
/// Get the current pointer-to-pointer, allocating it if it does not already exist. May
649649
/// acquire the GIL. Will never return nullptr.
650650
std::unique_ptr<InternalsType> *get_pp() {
651-
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
652-
if (get_num_interpreters_seen() > 1) {
653-
// Whenever the interpreter changes on the current thread we need to invalidate the
654-
// internals_pp so that it can be pulled from the interpreter's state dict. That is
655-
// slow, so we use the current PyThreadState to check if it is necessary.
656-
auto *tstate = get_thread_state_unchecked();
657-
if (!tstate || tstate->interp != last_istate_tls()) {
658-
gil_scoped_acquire_simple gil;
659-
if (!tstate) {
660-
tstate = get_thread_state_unchecked();
661-
}
662-
last_istate_tls() = tstate->interp;
663-
internals_p_tls() = get_or_create_pp_in_state_dict();
664-
}
665-
return internals_p_tls();
666-
}
667-
#endif
668-
if (!internals_singleton_pp_) {
669-
gil_scoped_acquire_simple gil;
670-
internals_singleton_pp_ = get_or_create_pp_in_state_dict();
671-
}
672-
return internals_singleton_pp_;
651+
gil_scoped_acquire_simple gil;
652+
return get_or_create_pp_in_state_dict();
673653
}
674654

675655
/// Drop all the references we're currently holding.

tests/test_multiple_interpreters.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,6 @@ def test():
240240
).lstrip()
241241

242242

243-
@pytest.mark.xfail(
244-
reason="Duplicate C++ type registration under multiple-interpreters, needs investigation.",
245-
# raises=interpreters.ExecutionFailed, # need to import the module
246-
strict=False,
247-
)
248243
@pytest.mark.skipif(
249244
sys.platform.startswith("emscripten"), reason="Requires loadable modules"
250245
)
@@ -281,11 +276,6 @@ def check_script_success_in_subprocess(code: str, *, rerun: int = 8) -> None:
281276
) from ex
282277

283278

284-
@pytest.mark.xfail(
285-
reason="Duplicate C++ type registration under multiple-interpreters, needs investigation.",
286-
raises=RuntimeError,
287-
strict=False,
288-
)
289279
@pytest.mark.skipif(
290280
sys.platform.startswith("emscripten"), reason="Requires loadable modules"
291281
)
@@ -342,11 +332,6 @@ def test_import_in_subinterpreter_after_main():
342332
)
343333

344334

345-
@pytest.mark.xfail(
346-
reason="Duplicate C++ type registration under multiple-interpreters, needs investigation.",
347-
raises=RuntimeError,
348-
strict=False,
349-
)
350335
@pytest.mark.skipif(
351336
sys.platform.startswith("emscripten"), reason="Requires loadable modules"
352337
)
@@ -427,11 +412,6 @@ def test_import_in_subinterpreter_before_main():
427412
)
428413

429414

430-
@pytest.mark.xfail(
431-
reason="Duplicate C++ type registration under multiple-interpreters, needs investigation.",
432-
raises=RuntimeError,
433-
strict=False,
434-
)
435415
@pytest.mark.skipif(
436416
sys.platform.startswith("emscripten"), reason="Requires loadable modules"
437417
)

0 commit comments

Comments
 (0)