cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Port zoneinfo module to use module state

Open sobolevn opened this issue 3 years ago • 4 comments

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

sobolevn avatar Nov 05 '22 18:11 sobolevn

I would like to listen to the opinion of the original author @pganssle

corona10 avatar Nov 06 '22 04:11 corona10

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.

pganssle avatar Nov 06 '22 04:11 pganssle

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

erlend-aasland avatar Nov 06 '22 21:11 erlend-aasland

I had some time free tonight, so I tried to complete my old branch and created a draft PR (gh-99218).

erlend-aasland avatar Nov 07 '22 21:11 erlend-aasland