On 24May2019 1018, Victor Stinner wrote:
Le ven. 24 mai 2019 à 18:14, Steve Dower <steve.dower@python.org> a écrit :
On 24May2019 0825, Victor Stinner wrote:
I started to modify Python **internals** to pass "runtime" and "tstate" in core files: pystate.c, ceval.c, pyerrors.c, signalmodule.c, pylifecycle.c, coreconfig.c, gcmodule.c, ...
This is why some of us have been advocating for a new structure - "PyContext" or similar - that can contain the information needed.
What do you plan to put in such PyContext?
We hadn't figured that out yet, but given that Yury found we needed contextvars because thread locals weren't sufficient after many years, I don't want to assume that the thread state is sufficient.
If we always pass the context struct by pointer, we can even expand its contents without breaking existing code. It just seems like a good engineering design to allow for future growth here.
Though I see you've gone ahead and modified the APIs already without waiting for discussion or review, so I guess this is how CPython works now *shrug*
Well, we had a discussion at Pycon and we agreed to add new parameters to pass a "context". But we didn't define how the context would look like. We also agreed to not touch the public API, only internals. As soon as it's internal, we are free to modify whenever.
Only from a forwards/backwards compatibility point of view, not for checking in code without review or discussion. Especially when you know there's a group of people interested and actively trying to participate in this area.
I went ahead to "discover" through the code what we need. So far, it seems like "it depends" :-) Each function has different needs.
Right, but for the most part, it's all going to come via the thread state, since that's our compatibility restriction. So probably best to pass that around consistently than try and select the minimal part of the interface for each function.
Or start with the PyContext struct that only contains the current thread state, and if we find reasons to move some things to the context level rather than the thread level, we have the ability to do that without breaking even ourselves.
Cheers, Steve