8000 gh-134160: Use multi-phase init in documentation examples by neonene · Pull Request #134296 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134160: Use multi-phase init in documentation examples #134296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
May 26, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a Py_mod_multiple_interpreters slot
  • Loading branch information
neonene authored May 22, 2025
commit 2d1095887f209e3c9afde774b133913f68410390
16 changes: 9 additions & 7 deletions Doc/extending/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,13 @@ optionally followed by an import of the module::

.. note::

If you define *static* extension types rather than heap-allocated types,
the module can cause the same problems as the legacy single-phase
initialization when removing entries from ``sys.modules`` or importing
compiled modules into multiple interpreters within a process
(or following a :c:func:`fork` without an intervening :c:func:`exec`).
In this case, at least the module should reject subinterpreters by using
a :c:type:`PyModuleDef_Slot` (``Py_mod_multiple_interpreters``).
If you declare a global variable or a local static one, the module can
cause the same problems as the legacy single-phase initialization when
removing entries from ``sys.modules`` or importing compiled modules into
multiple interpreters within a process (or following a :c:func:`fork` without an
intervening :c:func:`exec`). In this case, at least the module should
stop supporting subinterpreters through a :c:type:`PyModuleDef_Slot`
(:c:data:`Py_mod_multiple_interpreters`).

A more substantial example module is included in the Python source distribution
as :file:`Modules/xxlimited.c`. This file may be used as a template or simply
Expand Down Expand Up @@ -1279,6 +1279,8 @@ function must take care of initializing the C API pointer array::

static PyModuleDef_Slot spam_module_slots[] = {
{Py_mod_exec, spam_module_exec},
// Just use this while using a local static variable
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
{0, NULL}
};

Expand Down
Loading
0