feat: change PYBIND11_EMBEDDED_MODULE to multiphase init (#5665)

* Move embedded modules to multiphase init

So that they too can support multi-interpreter and nogil tags

* Update the multiple interpreter test for embedded module changes

* Add a note to embedded module docs about the new tags

* Oops, missed a warning pop

* Remove unused variable

* Update ci.yml

* Fix this embedded GIL test for free-threading

* Oops, need to use ptr() here

* This test created a subinterpreter when PYBIND11_SUBINTERPRETER_SUPPORT was off

So the fix is really this test should not be run in these older versions at all.

The hang was a GIL issue between the subinterpreters during pybind11::exception::what().

* fix: standard mutex for 3.13t

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
This commit is contained in:
b-pass
2025-05-18 09:39:26 -04:00
committed by GitHub
parent 094343c74a
commit 9afc9c4ffb
6 changed files with 70 additions and 21 deletions

View File

@@ -212,6 +212,11 @@ naturally:
assert(locals["message"].cast<std::string>() == "1 + 2 = 3");
}
``PYBIND11_EMBEDDED_MODULE`` also accepts
:func:`py::mod_gil_not_used()`,
:func:`py::multiple_interpreters::per_interpreter_gil()`, and
:func:`py::multiple_interpreters::shared_gil()` tags just like ``PYBIND11_MODULE``.
See :ref:`misc_subinterp` and :ref:`misc_free_threading` for more information.
Interpreter lifetime
====================

View File

@@ -155,6 +155,8 @@ following checklist.
within pybind11 that will throw exceptions on certain GIL handling errors
(reference counting operations).
.. _misc_free_threading:
Free-threading support
==================================================================
@@ -178,6 +180,8 @@ your code is thread safe. Modules must still be built against the Python free-t
enable free-threading, even if they specify this tag. Adding this tag does not break
compatibility with non-free-threaded Python.
.. _misc_subinterp:
Sub-interpreter support
==================================================================