-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
gh-116322: Add Py_mod_gil module slot #116882
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fa92cb4
Add Py_mod_gil module slot
swtaarrs 7edf796
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs 450aa41
Some review comments from Eric
swtaarrs 6bbd281
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs 47b9e26
Fix enabling the GIL, also support disabling the GIL
swtaarrs f7c3e50
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs 6c198e4
Fix module size in test_objecttypes
swtaarrs 554c5b4
Add missing : in Py_mod_gil documentation
swtaarrs cd187a0
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs 8057478
From Eric: better loop, move _PyImport_CheckGILForModule
swtaarrs a8f0943
Merge remote-tracking branch 'upstream/main' into cpython-mod-gil
swtaarrs bbb949e
Remove code to enable/disable the GIL (it will go in a different PR)
swtaarrs 7f1205e
Don't put PyModule_SetGIL() in the limited API
swtaarrs f8b02b3
Set m->md_gil in PyModule_FromDefAndSpec2, rename/guard PyModule_SetG…
swtaarrs d2bad05
Fix limited API version for Py_mod_gil
swtaarrs d7d59f0
Update NEWS entry for behavioral changes
swtaarrs ccd6e00
Mark all modules as not using GIL
swtaarrs 8846586
Merge remote-tracking branch 'upstream/main' into HEAD
swtaarrs 99bc5cb
Fix 'gil_slot set but not used' warning
swtaarrs 6882c13
Patch generator for Python-ast.c instead of just the file itself
swtaarrs da63df1
Update limited API version for _scproxy.c
swtaarrs 2998def
Fix _testconsole.c for Windows build
swtaarrs 77d1652
Fix winsound.c for Windows build
swtaarrs d1fe0cc
Mark more modules as not using the GIL
swtaarrs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Lib/test/test_importlib/extension/_test_nonmodule_cases.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Misc/NEWS.d/next/Core and Builtins/2024-03-12-13-51-09.gh-issue-116322.q8TcDQ.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
Unstable
andExperimental
in the name felt redundant, and in this comment, @ericsnowcurrently expressed a preference forPyModule_ExperimentalSetGIL()
overPyUnstable_Module_SetGIL()
.Does anyone else have strong feelings on whether it should be
PyUnstable_Module_ExperimentalSetGIL()
orPyUnstable_Module_SetGIL()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR here: #118645
IMO, the “experimental” is redundant. If we need “Experimental” too, we should rethink the entire PEP-689 naming convention.