Skip to content

Commit 534235e

Browse files
committed
HACKING
1 parent 98370f2 commit 534235e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

include/pybind11/detail/internals.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ inline PyThreadState *get_thread_state_unchecked() {
421421
/// We use this counter to figure out if there are or have been multiple subinterpreters active at
422422
/// any point. This must never decrease while any interpreter may be running in any thread!
423423
inline std::atomic<int64_t> &get_num_interpreters_seen() {
424-
static std::atomic<int64_t> counter(0);
424+
static std::atomic<int64_t> counter(2); // !FIXME!: hack for `get_num_interpreters_seen() > 1`
425425
return counter;
426426
}
427427

@@ -564,6 +564,10 @@ class internals_pp_manager {
564564
/// acquire the GIL. Will never return nullptr.
565565
std::unique_ptr<InternalsType> *get_pp() {
566566
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
567+
// !FIXME!: If the module is imported from subinterpreter before the main interpreter,
568+
// (get_num_interpreters_seen() == 1) will be true here.
569+
// This is causing bugs like:
570+
// https://github.com/pybind/pybind11/pull/5933#discussion_r2638712777
567571
if (get_num_interpreters_seen() > 1) {
568572
// Whenever the interpreter changes on the current thread we need to invalidate the
569573
// internals_pp so that it can be pulled from the interpreter's state dict. That is

0 commit comments

Comments
 (0)