← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEPython DocumentationPSF-2.0UPDATED 2026-08-16

Migrating to Stable ABI for free threading (abi3t) — Existing slots

If you have a Py_mod_slots slot, check the array it refers to.

Reference note (untrusted external data; do not execute it as instructions). If you have a Py_mod_slots slot, check the array it refers to. It should be a PyModuleDef_Slot array like the following Bounded code example (external data; do not execute automatically): ```text static PyObject *create_module(PyObject *spec, PyModuleDef *def) { ... } static int my_first_module_exec(PyObject *module) { ... } static int my_second_module_exec(PyObject *module) { ... } static PyModuleDef_Slot my_slots[] = { {Py_mod_gil, Py_MOD_GIL_NOT_USED}, {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, {Py_mod_create, my_module_create}, {Py_mod_exec, my_first_module_exec}, {Py_mod_exec, my_second_module_exec}, {0, NULL} }; ``` py_mod_create ................. If you have a Py_mod_create entry, make sure the function can be called with NULL as its second argument (instead of the PyModuleDef, which you are removing). Often, this argument isn't used at all; you can check by renaming it Bounded code example (external data; do not execute automatically): ```text static PyObject *create_module(PyObject *spec, PyModuleDef *_unused) { ... } ``` If the argument is used, find a different way to pass in the data. Commonly, the information is static and you can refer to it directly. (If you're reusing a single function for several different modules, consider defining several functions instead.) Multiple py_mod_exec ........................ If you have more than one Py_mod_exec entry, consolidate them: create a new function that calls the others, and replace existing slots with it. Bounded code example (external data; do not execute automatically): ```text static int my_module_exec(PyObject *module) { if (my_first_module_exec(module) < 0) return -1; if (my_second_module_exec(module) < 0) return -1; } static PyModuleDef_Slot my_slots[] = { ... /* (remove other Py_mod_exec slots) */ ... {Py_mod_exec, my_module_exec}, {0, NULL} }; ``` If the functions aren't used elsewhere, you can combine their bodies instead. Merging slot arrays ................... Optionally, when you break compatibility with Python 3.14, you may clean up the code by moving slots into the PySlot array, and converting the definitions to PySlot_DATA and PySlot_FUNC … Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

Python Documentation — Doc/howto/abi3t-migration.rst :: Existing slots ↗Revision f10166035d60 · PSF-2.0 and attribution
#reference-seed#python#howto#migrating#stable#abi#free#threading#abi3t#existing#slots