Python Free-Threaded Extension Readiness
When to Use
- A native Python extension must support a free-threaded CPython build.
- A project is considering
cp313t/cp314twheels or a GIL opt-out declaration. - Import works but stress, callback, teardown, or ThreadSanitizer runs fail.
- A release needs evidence that native code and dependencies are safe without the GIL.
Do not activate for pure-Python thread-pool tuning, ordinary asyncio debugging, or a package that explicitly does not plan to publish free-threaded support. For pure-Python compatibility, use CPython's free-threading Python HOWTO instead.
Prerequisites
- A regular CPython build and a matching free-threaded build.
- The project's normal native build and test toolchain.
- A small workload that crosses the extension boundary from at least two threads.
- Optional: a ThreadSanitizer-instrumented build for C/C++ race detection.
Never infer readiness from import success, a wheel tag, or a module GIL declaration alone. Run this workflow in disposable CI or a clean worktree; sanitizers and stress tests can be slow and nondeterministic.
Quick Reference
| Evidence | Minimum release-gate interpretation |
| --- | --- |
| sysconfig.get_config_var("Py_GIL_DISABLED") | Confirms the test interpreter is free-threaded |
| Py_mod_gil / PyUnstable_Module_SetGIL / binding equivalent | Declares whether import may leave the GIL disabled; it does not prove safety |
| Regular + free-threaded matrix | Separates ordinary regressions from no-GIL failures |
| Repeated multithread fixture | Exercises shared state, callbacks, and teardown |
| Dependency inventory | Prevents an unsafe transitive native module from being overlooked |
| ThreadSanitizer | Strong supplementary race evidence; investigate every finding |
Helper:
python3 scripts/audit_free_threaded.py evidence.json
python3 scripts/audit_free_threaded.py --require-tsan evidence.json
The helper reads local JSON only, makes no network calls, writes nothing, rejects malformed/non-finite input, and exits 0 for ready or not_applicable, 1 for an incomplete/unsafe gate, and 2 for invalid evidence. See