File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -602,6 +602,19 @@ 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+ //
608+ // For multi-interpreter support, the subinterpreters can be initialized concurrently, and
609+ // the first time this function may not be called in the main interpreter.
610+ // For example, a clean main interpreter that does not import any pybind11 module and then
611+ // spawns multiple subinterpreters using `InterpreterPoolExecutor` that each imports a
612+ // pybind11 module concurrently.
613+ //
614+ // Multiple subinterpreters may observe `get_num_interpreters_seen() <= 1` at the same
615+ // time, while `get_num_interpreters_seen() += 1` in `PYBIND11_MODULE(...)` is called
616+ // later.
617+
605618 // Whenever the interpreter changes on the current thread we need to invalidate the
606619 // internals_pp so that it can be pulled from the interpreter's state dict. That is
607620 // slow, so we use the current PyThreadState to check if it is necessary.
You can’t perform that action at this time.
0 commit comments