cpython
cpython copied to clipboard
Port zoneinfo module to use module state
Feature or enhancement
Following https://github.com/ericsnowcurrently/multi-core-python/wiki/0-The-Plan we need to convert _zoneinfo to use module state.
Pitch
Right now there are several global objects:
https://github.com/python/cpython/blob/47ab8480e71ab3949a336a94c7fd146b1fce595d/Modules/_zoneinfo.c#L23-L25
and
https://github.com/python/cpython/blob/47ab8480e71ab3949a336a94c7fd146b1fce595d/Modules/_zoneinfo.c#L96-L101
And one static type definition:
https://github.com/python/cpython/blob/47ab8480e71ab3949a336a94c7fd146b1fce595d/Modules/_zoneinfo.c#L93
If this is indeed planned to be fixed, I would love to work on it.
- PR: gh-99218
I would like to listen to the opinion of the original author @pganssle
I think I originally planned to do this but it made the implementation a bit more complicated and maybe all the pieces to do it weren't in place / stable yet, and after talking to Eric it seemed like it wasn't time sensitive back then.
I don't remember any major show stoppers, just, "This is hard enough, I should spend my effort points on other stuff that matters more." Which isn't to say there aren't show stoppers, just that I don't remember any.
I think the big thing to be aware of when doing this is that the weak cache is not for performance, it is guaranteeing specific semantics, detailed in PEP 615. So hopefully it is possible to do this while maintaining the relevant guarantees.
FWIW, I have a two year old branch (now rebased onto main) that converts PyZoneInfo_ZoneInfoType to a heap type and establishes a global state struct:
https://github.com/erlend-aasland/cpython/pull/new/isolate-zoneinfo
I had some time free tonight, so I tried to complete my old branch and created a draft PR (gh-99218).