brotlicffi icon indicating copy to clipboard operation
brotlicffi copied to clipboard

Support the free-threaded build of Python 3.14

Open ngoldbaum opened this issue 1 month ago • 4 comments

  • Avoids setting py_limited_api on the free-threaded build. This tells CFFI to build version-specific wheels instead of abi3 wheels.
  • Updates the test jobs to add 3.14t tests.
  • Updates the test jobs to only run tests for one python version by explicitly specifying a tox environment. Currently they run tests for several versions using interpreters that happen to be installed on the image.
  • Adds a lock to the Compressor and Decompressor class and ensures that all operations that non-atomically read or mutate state on either class happen while the lock is held. Rather than introduce possible scaling bottlenecks, I've set up the threading.Lock to always call acquire(blocking=False), and if the lock is already held by another thread, immediately raise an error. This enforces that it's not safe to share Compressor or Decompressor instances while compression or decompression operations are happening. This follows the approach in https://github.com/google/brotli/pull/1386/.
  • Adds tests based on https://github.com/google/brotli/pull/1386/. The timing is slightly different than what's in that PR - ping @eustas - you may want to look at this.
  • Updates wheel-building infrastructure to build cp314t wheels.

Open questions:

  • Should I add a thread safety section to the documentation? Where?
  • Should I add a pytest-run-parallel testing job to ensure there's no global state in the implementation of the pure functions in the API?

ngoldbaum avatar Nov 26 '25 22:11 ngoldbaum

Argh: the test timing is flaky. There's probably a better way to synchronize things but I'm running out of steam. Suggestions to improve the tests are very welcome :)

ngoldbaum avatar Nov 26 '25 22:11 ngoldbaum

It also occurred to me while working on this that the ubuntu wheel builds probably benefit from the new aarch64 CI runners on github actions. That would allow skipping the slow QEMU-emulated builds on ubuntu-latest.

ngoldbaum avatar Nov 26 '25 23:11 ngoldbaum

ping @cclauss @zmedico - do you want to look this over?

ngoldbaum avatar Dec 03 '25 04:12 ngoldbaum

Thank you @ngoldbaum, sorry I did not see the initial notification that this PR was opened. I can take a look, but please @cclauss and @zmedico take a look as well.

sethmlarson avatar Dec 10 '25 15:12 sethmlarson