Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the free-threaded build of CPython 3.13 #1455

Open
1 of 8 tasks
lysnikolaou opened this issue Dec 20, 2024 · 0 comments
Open
1 of 8 tasks

Support the free-threaded build of CPython 3.13 #1455

lysnikolaou opened this issue Dec 20, 2024 · 0 comments

Comments

@lysnikolaou
Copy link

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant