Skip to content

Commit 7f96223

Browse files
committed
gh-134160: Improve note on multi-phase init & subinterpreters
1 parent 9bf03c6 commit 7f96223

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Doc/c-api/module.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,13 @@ using :c:func:`PyModule_GetState`), or its contents (such as the module's
302302
:attr:`~object.__dict__` or individual classes created with :c:func:`PyType_FromSpec`).
303303
304304
All modules created using multi-phase initialization are expected to support
305-
:ref:`sub-interpreters <sub-interpreter-support>`. Making sure multiple modules
306-
are independent is typically enough to achieve this.
305+
:ref:`sub-interpreters <sub-interpreter-support>`.
306+
Typically, extensions ensure this in one of these ways:
307+
308+
- :ref:`isolating module instances <isolating-extensions-howto>`,
309+
- :ref:`raising an error on repeated initialization <isolating-extensions-optout>`, or
310+
- limiting a module to the main interpreter using
311+
:c:data:`Py_mod_multiple_interpreters`.
307312
308313
To request multi-phase initialization, the initialization function
309314
(PyInit_modulename) returns a :c:type:`PyModuleDef` instance with non-empty

Doc/howto/isolating-extensions.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ possible, consider explicit locking.
168168
If it is necessary to use process-global state, the simplest way to
169169
avoid issues with multiple interpreters is to explicitly prevent a
170170
module from being loaded more than once per process—see
171-
`Opt-Out: Limiting to One Module Object per Process`_.
171+
:ref:`isolating-extensions-optout`.
172172

173173

174174
Managing Per-Module State
@@ -207,6 +207,8 @@ An example of a module with per-module state is currently available as
207207
example module initialization shown at the bottom of the file.
208208

209209

210+
.. _isolating-extensions-optout:
211+
210212
Opt-Out: Limiting to One Module Object per Process
211213
--------------------------------------------------
212214

0 commit comments

Comments
 (0)