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-134160: Use multi-phase init in documentation examples by neonene · Pull Request #134296 · python/cpython Conversation
|
|
cc @erlend-aasland @encukou Just in case you're interested. |
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.
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.
Co-authored-by: Adam Turner <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
| static PyModuleDef_Slot emb_module_slots[] = { | ||
| {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, | ||
| {Py_mod_gil, Py_MOD_GIL_NOT_USED}, | ||
| {0, NULL} | ||
| }; |
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.
Having done trial conversions of NumPy to multi-phase, I think we should include the relevant PY_VERSION_HEX checks. Both Py_mod_multiple_interpreters and Py_mod_gil were added very recently.
If we agree on adding these checks, we should add them for all relevant PyModuleDef_Slot structs. It is verbose, but aids in the copy-and-paste scenario.
| static PyModuleDef_Slot emb_module_slots[] = { | |
| {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, | |
| {Py_mod_gil, Py_MOD_GIL_NOT_USED}, | |
| {0, NULL} | |
| }; | |
| static PyModuleDef_Slot emb_module_slots[] = { | |
| #if PY_VERSION_HEX >= 0x030C00F0 // Python 3.12+ | |
| // signal that this module can be imported in isolated subinterpreters | |
| {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, | |
| #endif | |
| #if PY_VERSION_HEX >= 0x030D00F0 // Python 3.13+ | |
| // signal that this module supports running without an active GIL | |
| {Py_mod_gil, Py_MOD_GIL_NOT_USED}, | |
| #endif | |
| {0, NULL} | |
| }; |
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.
Alternative:
| static PyModuleDef_Slot emb_module_slots[] = { | |
| {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, | |
| {Py_mod_gil, Py_MOD_GIL_NOT_USED}, | |
| {0, NULL} | |
| }; | |
| static PyModuleDef_Slot emb_module_slots[] = { | |
| #ifdef Py_mod_multiple_interpreters | |
| // signal that this module can be imported in isolated subinterpreters | |
| {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, | |
| #endif | |
| #ifdef Py_mod_gil | |
| // signal that this module supports running without an active GIL | |
| {Py_mod_gil, Py_MOD_GIL_NOT_USED}, | |
| #endif | |
| {0, NULL} | |
| }; |
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.
Can this PR omit these slots entirely?
IMO, they should be introduced later, after you compile your first module, along with a longer discussion about isolated state & thread safety.
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.
Agree better to keep simple. @neonene perhaps remove the gil and interpreter slots from where we've added them in this PR unless they were already present?
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.
Removed, but not all. I can complete.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Other places to update:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Adam Turner <[email protected]>
|
One of my motivation: https://discuss.python.org/t/proposal-officially-deprecate-support-for-legacy-single-phase-init-extension-modules/89262/26 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @neonene for the PR, and @AA-Turner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…onGH-134296) (cherry picked from commit 96905bd) Co-authored-by: neonene <[email protected]> Co-authored-by: Adam Turner <[email protected]>
…onGH-134296) (cherry picked from commit 96905bd) Co-authored-by: neonene <[email protected]> Co-authored-by: Adam Turner <[email protected]>
|
GH-134753 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-134754 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…134296) (#134753) gh-134160: Use multi-phase init in documentation examples (GH-134296) (cherry picked from commit 96905bd) Co-authored-by: neonene <[email protected]> Co-authored-by: Adam Turner <[email protected]>
…134296) (#134754) gh-134160: Use multi-phase init in documentation examples (GH-134296) (cherry picked from commit 96905bd) Co-authored-by: neonene <[email protected]> Co-authored-by: Adam Turner <[email protected]>
| You can also define a new exception that is unique to your module. | ||
| For this, you can declare a static global object variable at the beginning | ||
| of the file:: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is not correct for multi-phase initialization, without preventing the exec function from other module instances from overriding this pointer.
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.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it's fine -- module state deserves a better explanation a bit later in the tutorial. And the ImportError being added in the next PR is a good thing to show.
The main thing I'd do differently is not backporting to 3.13 -- that's like pushing directly to production. 3.14 is out in a few months; that sounds like a good amount of time for this all to spend in prerelease.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…on#134296) Co-authored-by: Adam Turner <[email protected]>
…on#134296) Co-authored-by: Adam Turner <[email protected]>
…on#134296) Co-authored-by: Adam Turner <[email protected]>
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.