-
-
Notifications
You must be signed in to change notification settings - Fork 186
Closed
Labels
Description
Is your feature request related to a problem?
No response
Describe the solution you'd like
Hey all! 👋
I took the liberty of looking into adding support for the 3.13 free-threaded build of CPython after multidict (I also plan to look at other libraries under the aio-libs organization). This aims to be a tracking issue for all work necessary to support it, for which I'm going to open a PR shortly.
- Set up CI for free-threading
- Audit the Cython extension module for thread-safety issues
- The only issues seems to be the usage of a statically allocated buffer for the
Writerstruct. That's fairly straightforward to solve.
- The only issues seems to be the usage of a statically allocated buffer for the
- Audit the Python code for thread-safety issues
- One fairly complicated thing to figure out was that there's some thread safety issues in the Python code as well. This stems from havily using non-thread-local caches when creating
URLinstances. Instantiating aURLwith a string url for example callsencode_urlwhich uses anlru_cache. This means that multiple threads might end up sharing the same object, even if theURLobject appears to have been created locally. There's a couple possible solution to this:- Disable
lru_cacheunder the free-threaded build so that object sharing between threads is more straightfoward. - Instead of using
lru_cacheto cache theURLobject itself, it could instead cache the immutable parts that make up aURL.
- Disable
- One fairly complicated thing to figure out was that there's some thread safety issues in the Python code as well. This stems from havily using non-thread-local caches when creating
- Mark the Cython extension module as thread-safe with setting
freethreading_compatiblein the cython directives (can be easily done throughpyproject.toml). - Build wheels for the free-threaded build.
Hope this all sounds good! Let me know in case there's something that doesn't seem right.
Describe alternatives you've considered
- We could say that people testing on the free-threaded build should only install the pure-Python wheels, but that doesn't seem like the best say forward, since the required changes are not that intrusive.
Additional context
No response
Code of Conduct
- I agree to follow the aio-libs Code of Conduct
Reactions are currently unavailable