-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-116322: Add Py_mod_gil module slot #116882
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
Changes from 23 commits
fa92cb4
7edf796
450aa41
6bbd281
47b9e26
f7c3e50
6c198e4
554c5b4
cd187a0
8057478
a8f0943
bbb949e
7f1205e
f8b02b3
d2bad05
d7d59f0
ccd6e00
8846586
99bc5cb
6882c13
da63df1
2998def
77d1652
d1fe0cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -411,6 +411,31 @@ The available slot types are: | |
|
|
||
| .. versionadded:: 3.12 | ||
|
|
||
| .. c:macro:: Py_mod_gil | ||
|
|
||
| Specifies one of the following values: | ||
|
|
||
| .. c:macro:: Py_MOD_GIL_USED | ||
|
|
||
| The module depends on the presence of the global interpreter lock (GIL), | ||
| and may access global state without synchronization. | ||
|
|
||
| .. c:macro:: Py_MOD_GIL_NOT_USED | ||
|
|
||
| The module is safe to run without an active GIL. | ||
|
|
||
| This slot is ignored by Python builds not configured with | ||
| :option:`--disable-gil`. Otherwise, it determines whether or not importing | ||
| this module will cause the GIL to be automatically enabled. See | ||
| :envvar:`PYTHON_GIL` and :option:`-X gil <-X>` for more detail. | ||
|
|
||
| Multiple ``Py_mod_gil`` slots may not be specified in one module definition. | ||
|
|
||
| If ``Py_mod_gil`` is not specified, the import machinery defaults to | ||
| ``Py_MOD_GIL_USED``. | ||
|
|
||
| .. versionadded: 3.13 | ||
|
|
||
| See :PEP:`489` for more details on multi-phase initialization. | ||
|
|
||
| Low-level module creation functions | ||
|
|
@@ -609,6 +634,19 @@ state: | |
|
|
||
| .. versionadded:: 3.9 | ||
|
|
||
| .. c:function:: int PyModule_ExperimentalSetGIL(PyObject *module, void *gil) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ehm, can this please be renamed to PyUnstable as suggested before? We have such naming schemes for a reason.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I'll get a PR ready. I went with this name because having both Does anyone else have strong feelings on whether it should be
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Indicate that *module* does or does not support running without the global | ||
| interpreter lock (GIL), using one of the values from | ||
| :c:macro:`Py_mod_gil`. It must be called during *module*'s initialization | ||
| function. If this function is not called during module initialization, the | ||
| import machinery assumes the module does not support running without the | ||
| GIL. This function is only available in Python builds configured with | ||
| :option:`--disable-gil`. | ||
| Return ``-1`` on error, ``0`` on success. | ||
|
|
||
| .. versionadded:: 3.13 | ||
|
|
||
|
|
||
| Module lookup | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import types | ||
| import unittest | ||
| from test.test_importlib import util | ||
|
|
||
| machinery = util.import_importlib('importlib.machinery') | ||
|
|
||
| from test.test_importlib.extension.test_loader import MultiPhaseExtensionModuleTests | ||
|
|
||
|
|
||
| class NonModuleExtensionTests: | ||
| setUp = MultiPhaseExtensionModuleTests.setUp | ||
| load_module_by_name = MultiPhaseExtensionModuleTests.load_module_by_name | ||
|
|
||
| def _test_nonmodule(self): | ||
| # Test returning a non-module object from create works. | ||
| name = self.name + '_nonmodule' | ||
| mod = self.load_module_by_name(name) | ||
| self.assertNotEqual(type(mod), type(unittest)) | ||
| self.assertEqual(mod.three, 3) | ||
|
|
||
| # issue 27782 | ||
| def test_nonmodule_with_methods(self): | ||
| # Test creating a non-module object with methods defined. | ||
| name = self.name + '_nonmodule_with_methods' | ||
| mod = self.load_module_by_name(name) | ||
| self.assertNotEqual(type(mod), type(unittest)) | ||
| self.assertEqual(mod.three, 3) | ||
| self.assertEqual(mod.bar(10, 1), 9) | ||
|
|
||
| def test_null_slots(self): | ||
| # Test that NULL slots aren't a problem. | ||
| name = self.name + '_null_slots' | ||
| module = self.load_module_by_name(name) | ||
| self.assertIsInstance(module, types.ModuleType) | ||
| self.assertEqual(module.__name__, name) | ||
|
|
||
|
|
||
| (Frozen_NonModuleExtensionTests, | ||
| Source_NonModuleExtensionTests | ||
| ) = util.test_both(NonModuleExtensionTests, machinery=machinery) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Extension modules may indicate to the runtime that they can run without the | ||
| GIL. Multi-phase init modules do so by calling providing | ||
| ``Py_MOD_GIL_NOT_USED`` for the ``Py_mod_gil`` slot, while single-phase init | ||
| modules call ``PyModule_ExperimentalSetGIL(mod, Py_MOD_GIL_NOT_USED)`` from | ||
| their init function. |
Uh oh!
There was an error while loading. Please reload this page.