Repository navigation
Declare the extension free-threading compatible - #278
Conversation
456dcff to
7d38b29
Compare
|
@benoit74 once look into this please thanks! |
|
We will need to fix CI with #277 so that tests run. Obviously pretty important on such a PR 🤣 |
Cython 3.1+ can build extensions compatible with free-threaded CPython, but a module must opt in with the freethreading_compatible directive; otherwise importing it re-enables the GIL. The module was tested with the GIL disabled and does not rely on it, so declare it compatible, build with Py_GIL_DISABLED on free-threaded interpreters, and drop the test-time workarounds that forced the GIL back on. Also make the Tests and QA workflows run on pull requests, as expected by the convention, so this PR's free-threaded tests actually run. Closes openzim#240 Refs openzim#277
7d38b29 to
b67fa64
Compare
|
@benoit74 Thanks for pointing this out. The Tests and QA workflows were only triggered by push, so no test ran on this PR. They now follow the convention used across the openZIM repositories, triggering on pull_request and on push to main only, which lets the 3.14t job actually exercise the free-threaded path. The CI trigger change is included in this PR and references #277. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #278 +/- ##
=======================================
Coverage 94.11% 94.11%
=======================================
Files 1 1
Lines 544 544
=======================================
Hits 512 512
Misses 32 32 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
benoit74
left a comment
There was a problem hiding this comment.
LGTM, thank you very much!
|
In the future we should avoid feature and unrelated CI changes in the same commit… 🙃 |
Declare the extension free-threading compatible
Declare the extension free-threading compatible
Declare the extension free-threading compatible
Cython 3.1+ can build extension modules that work on free-threaded CPython, but a module only runs without re-enabling the GIL if it opts in with the module-level
freethreading_compatibledirective. Without it, importing the module forces the GIL back on (with a runtime warning), so free-threaded builds gained nothing.The extension does not rely on the GIL: the C++ libzim calls are wrapped in
with nogil, and the only Python interaction is through thewith gilcallbacks, which already acquire the interpreter thread-state as needed. Declare the module free-threading compatible and build it withPy_GIL_DISABLEDon free-threaded interpreters, so it is compiled against the free-threaded API.The workarounds that forced the GIL back on are now unnecessary and removed:
cibuildwheeloverride running tests with-X gil=1oncp313t/cp314t,-X gil=1,READMEandCHANGELOGupdated accordingly.The
TestsandQAworkflows are also updated to run onpull_request(and onpushtomainonly), matching the convention used in the other openZIM repositories, so the free-threaded tests actually run on this PR (refs #277).Notes:
3.14t) job in CI is what actually exercises the no-GIL path.Closes #240
Refs #277