-
-
Notifications
You must be signed in to change notification settings - Fork 183
Surface multiphase init #3354
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
base: main
Are you sure you want to change the base?
Surface multiphase init #3354
Conversation
Hi Andrew. Could you explain to me what this singlephase/multiphase initialization and subinterpreters thing is about? Or if it's easier, where can I properly read about it? I'm uninformed about the topic. |
Here’s the pep for multi phase the reason I want to make this change is because of free threading. Disabling the GIL at a module level in single phase requires the use of unstable API, which can (and probably will) change on us at some arbitrary Python minor version update. Disabling the GIL at a module level in multi phase is as simple as defining a slot |
subinterpreters is another topic. The only reason it’s brought up here is because multiphase makes some assumptions that need to be handled for it |
Properly handling subinterpreters should be left off for a future pull |
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.
LGTM, thanks for the PR! 🎉
I'm still not a 100% clear on all refcounting aspects of this PR, but these are module level objects that are supposed to be immortal anyways, so overcounting references should practically be fine :)
Which part is confusing? |
I'm also uncertain about the ref counting in this PR, with PyModule_AddObjectRef. Reading over the multiphase init documentation it mentioned PyModule_AddObjectRef, so maybe Andrew you used it because it was mentioned there? |
5b61019
to
2d4f65f
Compare
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.
LGTM, thanks for the PR 🎉
Since disabling the GIL on singlephase initialization requires the use of
PyUnstable_*
calls, I would like to make use of multiphase initialization whenever possible. Here is a tentative implementation for an initial port forpygame.Surface
. Note that this is just for moving over to multiphase initialization and has nothing to do with free-threading. This should not affect current behavior in any way to the best of my understanding