Defining extension modules — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Exception Handling

Python Module Index

3.16.0a0 Documentation

Python/C API reference manual

importlib.machinery.ExtensionFileLoader

A C extension for CPython is a shared library (for example, a .so file on Linux, .pyd DLL on Windows), which is loadable into the Python process (for example, it is compiled with compatible compiler settings), and which

Extension export hook¶

A C extension for CPython is a shared library (for example, a .so file on Linux, .pyd DLL on Windows), which is loadable into the Python process (for example, it is compiled with compatible compiler settings), and which

Extension export hook¶

Added in version 3.15: Support for the PyModExport_<name> export hook was added in Python 3.15. The older way of defining modules is still available: consult either the PyInit function section or earlier versions of this

Extension export hook¶

Added in version 3.15: Support for the PyModExport_<name> export hook was added in Python 3.15. The older way of defining modules is still available: consult either the PyInit function section or earlier versions of this

free-threaded builds

Code in the export hook must never rely on the GIL: free-threaded builds of Python can only check the Py_mod_gil slot (or the lack of it) after the hook returns,

module.__package__

Python sets initial module attributes like __package__ and __loader__, and inserts the module object into sys.modules.

Multiple module instances¶

By default, extension modules are not singletons. For example, if the sys.modules entry is removed and the module is re-imported, a new module object is created and, typically, populated with fresh method and type object

Multiple module instances¶

By default, extension modules are not singletons. For example, if the sys.modules entry is removed and the module is re-imported, a new module object is created and, typically, populated with fresh method and type object

Isolating Extension Modules

By default, extension modules are not singletons. For example, if the sys.modules entry is removed and the module is re-imported, a new module object is created and, typically, populated with fresh method and type object