GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-116322: Add Py_mod_gil module slot by swtaarrs · Pull Request #116882 · python/cpython Conversation
|
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'll take a look on Monday. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
mostly LGTM
I've left a few comments and I have some feedback on the relationship between Py_mod_multiple_interpreters and Py_mod_gil.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@ericsnowcurrently I don't think there should be any code changes as a result of our big sub-thread. Please let me know if that's wrong! Before this is ready for another review, I need to make some other changes. It looks like the consensus in Discord is that we should enable the GIL when calling a module init function, because we don't know before the call if it's a single-phase init module that needs the GIL. Then if it's a multi-phase init module that provides The only nontrivial (but not too complicated) part of this will be adding a function to disable the GIL safely. It should also move the GIL-related logic up out of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Yeah, I think you're right. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
More details: - Fix a race while enabling the GIL by checking if the GIL was enabled between a no-op call to `_PyEval_AcquireLock()` and the thread attaching, and trying again if it was. - Enable the GIL before running a module init function, since we can't know if it's a single-phase init module that doesn't support free-threading. Look at the state of the module after initialization to determine if it's safe to disable the GIL again. - Add `PyModule_SetGIL()`, which can be used by single-phase init modules to declare that they support running without the GIL. - Change `gil->enabled` from a simple on/off switch to a count of active requests to enable the GIL. This allows us to support multiple interleaved imports that each independently track whether the GIL should remain enabled. See the big comment in `pycore_ceval.h` for more details.
|
I have made the requested changes; please review again. This should be ready for review again. It grew in scope a bit, and now includes support for single-phase init modules (gh-117526) (some details are in the commit message). With the infrastructure needed to properly support multi-phase init modules, supporting single-phase init modules is just a few extra lines, but I can pull it out into a separate PR if anyone wants. One specific thing I'd like input on is the timing of the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
!buildbot nogil |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 77d1652 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I found a few more modules that I missed during some testing, and will push a commit to add those shortly. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
!buildbot nogil |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @swtaarrs for commit d1fe0cc 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| .. versionadded:: 3.9 | ||
|
|
||
| .. c:function:: int PyModule_ExperimentalSetGIL(PyObject *module, void *gil) |
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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 and Experimental in the name felt redundant, and in this comment, @ericsnowcurrently expressed a preference for PyModule_ExperimentalSetGIL() over PyUnstable_Module_SetGIL().
Does anyone else have strong feelings on whether it should be PyUnstable_Module_ExperimentalSetGIL() or PyUnstable_Module_SetGIL()?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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 pythongh-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).
| } | ||
| } | ||
| m->md_def = module; | ||
| #ifdef Py_GIL_DISABLE |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should be Py_GIL_DISABLED.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This means: "Do not re-enable the GIL when importing rl.readline." See python/cpython#116322 See python/cpython#116882
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.