-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New PEP: A Per-Interpreter GIL #2212
New PEP: A Per-Interpreter GIL #2212
Conversation
Does this really need to be a PEP if it is just basically going to be a white paper trying to justify a per-interpreter GIL (which has not been approved to occur)? |
I don't have an opinion yet on whether this particular document should be a
PEP or a white paper, but I think there are two decisions ahead of us that
*do* require a PEP (maybe one PEP together?):
- Are we going to implement a per-interpreter GIL?
- Should we adopt immortal objects?
The (IMO strong) connection between the two is that if we have a
per-interpreter GIL we cannot share *any* objects between interpreters
unless we make all such objects immortal (and immutable). And while we have
some possible hacks that could enable per-interpreter GIL without immortal
objects, they are not pretty and pose a risk for ABI and API compatibility.
OTOH immortal objects have a certain cost associated with them.
Of course another, related decision is what to do with Sam Gross's nogil
work.
And yet another issue to decide is, *if* we get a per-interpreter GIL, what
API to use to share data between interpreters (since you can't share
mutable objects). This is covered by PEP 554, but that hasn't been accepted
yet, and arguably the API there is a bit baroque.
Presumably all these things have to be discussed by the SC. Would it
require a PEP to get them on the SC agenda? If so, we had better get
cracking, or none of this will make it into 3.11.
Some guidance from the SC (on the meta-issue of whether PEPs are required
and who is expected to write them) would be appreciated.
…On Thu, Jan 6, 2022 at 2:26 PM Brett Cannon ***@***.***> wrote:
Does this really need to be a PEP if it is just basically going to be a
white paper trying to justify a per-interpreter GIL (which has not been
approved to occur)?
—
Reply to this email directly, view it on GitHub
<#2212 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAWCWMTBGJSPY36ZP67MY33UUYJKLANCNFSM5LIRDSCA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
|
https://bugs.python.org/issue40077 Convert static types to heap types: use PyType_FromSpec() | ||
https://bugs.python.org/issue42972 [C API] Heap types (PyType_FromSpec) must fully implement the GC protocol | ||
https://bugs.python.org/issue15870 PyType_FromSpec should take metaclass as an argument | ||
https://bugs.python.org/issue45113 [subinterpreters][C API] Add a new function to create PyStructSequence from Heap. |
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.
Maybe we can add this issue too.
https://bugs.python.org/issue1635741
On this narrow question, given that we don't have any other good repository for these types of documents, it doesn't bother me for things like this to be information PEPs. And even so, if they weren't PEPs, how would they be discoverable? |
I'm under the impression that an informational PEP is essentially a whitepaper. What PEP 1 says looks like a definition of a whitepaper. (Or is my English failing me and we're talking about a different meaning of the term?) |
IMO this topic is too wide to fit everything into a single PEP. I suggest to split it into multiple (smaller) PEPs:
For static types and singletons, it seems like you are supporter of immortal objects. Well, I dislike immortal objects and there are other solutions to these problems. For example, make singletons per interpreter, and keep static types in the main interpreter, but modify C extensions to call functions to get types, in C extensions which needs to be compatible with sub-interpreters (all stdlib extensions must be modified this way). IMO the key is the migration plan. How to introduce this feature without requiring all C extensions to be written on a flag day? It has been discussed multiple times to add a flag to a C extension to opt in for sub-interpreters support. Moreover, IMO we should also consider to support multiple interpreters sharing the same GIL ("shared GIL", current behavior) and interprereters having their own GIL ("isolated"). Again, it's to have a more smooth migration plan, to avoid having to rewrite all C extensions on a flag day. |
Yeah, after the conversation here it makes sense to me to split the PEP into the decidable parts (and maybe not even do an informational PEP). |
This could be split into two parts:
And we should probably address the downsides of separate GILs:
|
This would be good and would benefit PEP 554 as well. However, I'm worried that I don't have enough time to do all these PEPs at once and still get anything else done. This PEP doesn't seem like it would add enough value to make it worth it. (The general points would just go into other PEPs, with not as much detail.)
To me, the devguide would be a better place for this. Aside from guidelines for the transition to per-interpreter, we would also need to cover any constraints core devs need to keep in mind relative to subinterpreters. We would also document any related tooling, e.g. c-analyzer (if that survives). This information would be valuable well after the GIL becomes per-interpreter.
Why would these be separate PEPs?
This is basically already covered by PEP 630.
That's pretty much exactly what I was planning on until recently. 🙂 At first I looked into immortal objects because they solve the problem so much more simply. However, there didn't seem to be a good way to work around the performance penalty. So I focused on per-interpreter objects (and successfully prototyped most of it). However, now immortal objects may be possible without the penalty. I'm going to do some benchmarking on the current branch. If they work out then I'd rather go with that because it is so much simpler. Either way we should consider deprecating all the objects in the C-API, and provide lookup functions as a replacement.
No extensions will need to be rewritten. In subinterpreters created via If an extension wants to be used in subinterpreters that do not share a GIL, they would have to be isolated (PEPs 489/630) first. However, that would be new in 3.11, so there is not compatibility issue. Existing code will keep working.
PEP 489 says that if an extension implements multi-phase init then it must support subinterpreters (and reloading, etc.).
That is exactly the plan. |
FYI, PEP 679 is now taken. |
The SC talked about this and if you want to move forward with an informational PEP that outlines plans, @ericsnowcurrently , then that's fine. We do want to be very clear, though, that it doesn't give tacit approval for the idea, just a place for you to collect and write down what you want to accomplish and how you plan to pull it off. We may also to move/copy it somewhere else in the future as we are now talking about how to handle communication of these large projects. |
I'll be posting a PEP just about immortal objects soon, as well a more focused one about per-interpreter GIL. Both will be leaner this this one. |
This is an informational PEP explaining the issues and work around making the GIL per-interpreter.
(I hope to publish/post later this week, but figured I'd get the meat of it up now so I can point people at it.)