Skip to content

Add support for free-threaded Python #225

Open

Description

@gi0baro

With free-threaded Python shortly leaving the experimental stage (with 3.14) would be nice to have wheels published for 3.13t and 3.14t variants.

Activity

  1. lelit commented on Jul 31, 2025

    @lelit
    Contributor

    To be honest, while I have read announcements and the like about FT, I don't know what changes on a C++ extension would be required: I doubt it's just a matter of recompiling against a different variant of the interpreter.

    So, first step would be to collect some specific info, or even examples of some project that already did that.

  2. gi0baro commented on Jul 31, 2025

    @gi0baro
    Author

    So, first step would be to collect some specific info, or even examples of some project that already did that.

    I maintain some Rust based extensions for Python, and in my experience the steps involved usually are:

    1. check the extension code is sound and thread-safe
    2. patch/refactor code that doesn't comply with point 1
    3. declare in the extension module(s) the free-threaded support
    4. compile the wheel against the different interpreter variants

    I'd say the free-threading guide has some very-well written details about the whole process.

  3. lelit commented on Aug 3, 2025

    @lelit
    Contributor

    Thank you Giovanni, I read that guide (actually re-read, but now with a particular goal in mind 😉).
    I have upgraded the cibuildwheel used on GH Actions to build wheels and run the tests on supported snakes, so I'm going to try to enable the free threaded variant of Python 3.14.
    I wonder if you could provide a simple-but-not-trivial test case to exercise the library with more than one thread, or point me in the right direction?

  4. gi0baro commented on Aug 10, 2025

    @gi0baro
    Author

    hey @lelit, sorry for the late reply.

    I guess I don't have any particular suggestions in terms of testing, other than wrapping lib calls in a function and spawning 2 or more threading.Thread(target=yourfunction). I'd say it also really depends on how your tests are designed.

  5. lelit commented on Aug 22, 2025

    @lelit
    Contributor

    I spent some time playing with this, and pushed some related commits in the free-threaded branch: note that that is just an experiment right now, and it surely need some more competent eye than mine to assert it is sensible.

    That said, I manually installed the pytest-freethreaded plugin, and followed the suggested phases in its README: I've got some crashes in the tests that are using either the tracemalloc library or the sys.getrecursionlimit() function, but skipping those tests under the "no-GIL" variant, everything seems working.

    I still have no clue at all whether that tells something positive or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions