The Wayback Machine - https://web.archive.org/web/20240325093833/https://github.com/python/cpython/pull/116882
Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

swtaarrs
Copy link
Member

@swtaarrs swtaarrs commented Mar 15, 2024

This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL.

PEP 703 called the constant for the slot Py_mod_gil_not_used; I went with Py_MOD_GIL_NOT_USED for consistency with gh-104148.

A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If -v is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).


📚 Documentation preview 📚: https://cpython-previews--116882.org.readthedocs.build/

@swtaarrs
Copy link
Member Author

The code here is ready, but I'll keep it as a draft until gh-116749 and gh-116329 are done, since this doesn't do anything when the GIL is enabled by default. I changed the default locally to test this as it works as intended.

@swtaarrs
Copy link
Member Author

I think it does make sense to land this now after all. The code won't function as intended until the GIL is disabled by default, but it will be nice to have the module slot available while I work on gh-116738, so I can tag modules as they're ready.

This is structured such that there shouldn't be any behavioral differences until the GIL is disabled by default, except when a --disable-gil build is run with -v, when it will print a single line for every non-free-threading-safe module that's loaded.

@swtaarrs swtaarrs marked this pull request as ready for review March 22, 2024 21:54
@swtaarrs swtaarrs requested a review from colesbury March 22, 2024 21:54
@ericsnowcurrently
Copy link
Member

I'll take a look on Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants