Support free-threaded Python 3.14 #176
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are you trying to accomplish?
With the release of Python 3.14, free-threading is no longer considered experimental, and many packages are now being updated to support free-threaded Python. I'd like for
ciso8601to support free-threaded Python.Related issue: #175
What approach did you choose and why?
Most of the library code is already stateless and re-entrant, so not many changes were needed. The one global state,
tz_cache, is now guarded by aPyMutexin the free-threaded build.Testing was done on
unittest-ftto spot any potential failures from race conditions, and there didn't seem to be any.What should reviewers focus on?
Potential thread safety issues I've missed. I've had Gemini look it over, but I still worry I missed something, since this is my first time looking at the library's code.
The impact of these changes
There is a minor performance penalty associated with synchronizing access to
tz_cache. On the timestamp with timezone benchmark, Python 3.14t performs slightly worse than Python 3.14 (69.7ns vs 66.4ns). This is still better than not caching at all (~80ns). There didn't seem to be any impact when parsing timestamps without timezone.Testing
tox.inihas already been updated to useunittest-ft, so testing the new changes should just be runningtox.