port-to-free-threaded-python
Make a Python package work correctly on the free-threaded (no-GIL) CPython build (PEP 703; the cp313t/cp314t "t" ABI) and declare that it does, so importing it does not silently re-enable the GIL. Covers the pure-Python thread-safety pass (mutable global/class state, caches, contextvars vs threading.local) and, for C/C++/Cython/pybind11/nanobind/Rust-PyO3 extensions, declaring support (Py_mod_gil / PyUnstable_Module_SetGIL / the per-binding flag), fixing data races with critical sections (Py_BEGIN_CRITICAL_SECTION), PyMutex, atomics and thread-local state, the borrowed-reference hazards and their strong-reference replacements (PyList_GetItemRef, PyDict_GetItemRef), building cp3Xt wheels (meson-python, scikit-build-core, maturin, setuptools, cibuildwheel), and testing under load with ThreadSanitizer and pytest-run-parallel. Use to add free-threading / no-GIL / nogil / free-threaded / PEP 703 support, ship a cp313t/cp314t wheel, or stop the GIL being re-enabled. For a single stable-ABI abi3t wheel (3.15+) pair it with port-to-python-limited-api.
Pinned to revision 0c51c24122b3, so it is the text this page describes rather than whatever the author pushed since.
Files
- skills/port-to-free-threaded-python/SKILL.md
- skills/port-to-free-threaded-python/AGENTS.md
- skills/port-to-free-threaded-python/README.md
- skills/port-to-free-threaded-python/reference/background.md
- skills/port-to-free-threaded-python/reference/build-and-test.md
- skills/port-to-free-threaded-python/reference/declaring-support.md
- skills/port-to-free-threaded-python/reference/thread-safety.md
Every link opens the file at its source, pinned to the revision this page describes.