From 534235ea559247f7a4984174f57f809b90a93af4 Mon Sep 17 00:00:00 2001 From: Xuehai Pan Date: Mon, 22 Dec 2025 15:44:51 +0800 Subject: [PATCH] HACKING --- include/pybind11/detail/internals.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 44d9f9e27..0a2b03c80 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -421,7 +421,7 @@ inline PyThreadState *get_thread_state_unchecked() { /// We use this counter to figure out if there are or have been multiple subinterpreters active at /// any point. This must never decrease while any interpreter may be running in any thread! inline std::atomic &get_num_interpreters_seen() { - static std::atomic counter(0); + static std::atomic counter(2); // !FIXME!: hack for `get_num_interpreters_seen() > 1` return counter; } @@ -564,6 +564,10 @@ public: /// acquire the GIL. Will never return nullptr. std::unique_ptr *get_pp() { #ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT + // !FIXME!: If the module is imported from subinterpreter before the main interpreter, + // (get_num_interpreters_seen() == 1) will be true here. + // This is causing bugs like: + // https://github.com/pybind/pybind11/pull/5933#discussion_r2638712777 if (get_num_interpreters_seen() > 1) { // Whenever the interpreter changes on the current thread we need to invalidate the // internals_pp so that it can be pulled from the interpreter's state dict. That is