From 6d2b9d2cc1450c93cea252fea37baaf639d981b0 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 28 Jul 2023 12:50:35 -0600 Subject: [PATCH 1/4] Add a doc entry for Py_mod_multiple_interpreters. --- Doc/c-api/module.rst | 26 ++++++++++++++++++++++++++ Doc/howto/isolating-extensions.rst | 2 ++ 2 files changed, 28 insertions(+) diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index fa5e97846e7bc3..e0549beec4ce0e 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -376,6 +376,32 @@ The available slot types are: If multiple ``Py_mod_exec`` slots are specified, they are processed in the order they appear in the *m_slots* array. +.. c:macro:: Py_mod_multiple_interpreters + + Specifies one of the following values: + + .. c:macro:: Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED + + The module does not support being imported in subinterpreters. + + .. c:macro:: Py_MOD_MULTIPLE_INTERPRETERS_SUPPORTED + + The module supports being imported in subinterpreters, + but only when they share the main interpreter's GIL. + (See :ref:`isolating-extensions-howto`.) + + .. c:macro:: Py_MOD_PER_INTERPRETER_GIL_SUPPORTED + + The module supports being imported in subinterpreters, + even when they have their own GIL. + (See :ref:`isolating-extensions-howto`.) + + Multiple ``Py_mod_multiple_interpreters`` slots may not be specified + in one module definition. + + If ``Py_mod_multiple_interpreters`` is not specified, the import + machinery defaults to ``Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED``. + See :PEP:`489` for more details on multi-phase initialization. Low-level module creation functions diff --git a/Doc/howto/isolating-extensions.rst b/Doc/howto/isolating-extensions.rst index 60854c3c034d73..2551fbe87b5c2a 100644 --- a/Doc/howto/isolating-extensions.rst +++ b/Doc/howto/isolating-extensions.rst @@ -1,5 +1,7 @@ .. highlight:: c +.. _isolating-extensions-howto: + *************************** Isolating Extension Modules *************************** From 987eb2aeece6584987e682e3a420096670295858 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 28 Jul 2023 13:53:20 -0600 Subject: [PATCH 2/4] Clarify the doc entry. --- Doc/c-api/module.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index e0549beec4ce0e..fbfa46667a7953 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -396,6 +396,9 @@ The available slot types are: even when they have their own GIL. (See :ref:`isolating-extensions-howto`.) + This slot determines whether or not importing this module + in a subinterpreter will fail. + Multiple ``Py_mod_multiple_interpreters`` slots may not be specified in one module definition. From 292357651f8e0ae94b2b4b24294f6c1ec74e78a8 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 28 Jul 2023 13:56:47 -0600 Subject: [PATCH 3/4] Add a ref. --- Doc/c-api/init.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 60912a1ecaede2..dd53fe2bc95696 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -1287,6 +1287,7 @@ function. You can create and destroy them using the following functions: in any thread where the sub-interpreter is currently active. Otherwise only multi-phase init extension modules (see :pep:`489`) may be imported. + (Also see :c:macro:`Py_mod_multiple_interpreters`.) This must be ``1`` (non-zero) if :c:member:`~PyInterpreterConfig.use_main_obmalloc` is ``0``. From b8b5eb3b9fe2860d948347bd477a57b45e9c1481 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 31 Jul 2023 16:00:54 -0600 Subject: [PATCH 4/4] Add a versionadded. --- Doc/c-api/module.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index fbfa46667a7953..e37505f6450a30 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -405,6 +405,8 @@ The available slot types are: If ``Py_mod_multiple_interpreters`` is not specified, the import machinery defaults to ``Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED``. + .. versionadded:: 3.12 + See :PEP:`489` for more details on multi-phase initialization. Low-level module creation functions