You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 Writer struct. That's fairly straightforward to solve.
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 URL instances. Instantiating a URL with a string url for example calls encode_url which uses an lru_cache. This means that multiple threads might end up sharing the same object, even if the URL object appears to have been created locally. There's a couple possible solution to this:
Disable lru_cache under the free-threaded build so that object sharing between threads is more straightfoward.
Instead of using lru_cache to cache the URL object itself, it could instead cache the immutable parts that make up a URL.
Mark the Cython extension module as thread-safe with setting freethreading_compatible in the cython directives (can be easily done through pyproject.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
The text was updated successfully, but these errors were encountered:
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 theaio-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.Writer
struct. That's fairly straightforward to solve.URL
instances. Instantiating aURL
with a string url for example callsencode_url
which uses anlru_cache
. This means that multiple threads might end up sharing the same object, even if theURL
object appears to have been created locally. There's a couple possible solution to this:lru_cache
under the free-threaded build so that object sharing between threads is more straightfoward.lru_cache
to cache theURL
object itself, it could instead cache the immutable parts that make up aURL
.freethreading_compatible
in the cython directives (can be easily done throughpyproject.toml
).Hope this all sounds good! Let me know in case there's something that doesn't seem right.
Describe alternatives you've considered
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: