Skip to content

Commit 8e5bb6e

Browse files
committed
Add a warning comment
1 parent 3e77ce9 commit 8e5bb6e

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

include/pybind11/detail/internals.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,15 @@ class internals_pp_manager {
602602
/// acquire the GIL. Will never return nullptr.
603603
std::unique_ptr<InternalsType> *get_pp() {
604604
#ifdef PYBIND11_HAS_SUBINTERPRETER_SUPPORT
605+
// WARNING: We cannot use `get_num_interpreters_seen() > 1` here to create a fast path for
606+
// the single-interpreter case.
607+
// For multi-interpreter support, the subinterpreters can be initialized concurrently, such
608+
// as using `InterpreterPoolExecutor` in Python. The first time this function may not be
609+
// called in the main interpreter, e.g., a clean main interpreter that does not import any
610+
// pybind11 module. Multiple subinterpreters may observe `get_num_interpreters_seen() <= 1`
611+
// at the same time, while `get_num_interpreters_seen() += 1` in `PYBIND11_MODULE(...)` is
612+
// called later.
613+
605614
// Whenever the interpreter changes on the current thread we need to invalidate the
606615
// internals_pp so that it can be pulled from the interpreter's state dict. That is
607616
// slow, so we use the current PyThreadState to check if it is necessary.

0 commit comments

Comments
 (0)