Skip to content

Commit

Permalink
Document Cython's freethreading_compatible directive
Browse files Browse the repository at this point in the history
  • Loading branch information
lysnikolaou committed Jul 15, 2024
1 parent 48b28b3 commit 2f787b9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions docs/porting.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ Extension modules need to explicitly indicate they support running with the GIL
disabled, otherwise a warning is printed and the GIL is re-enabled at runtime
after importing a module that does not support the GIL.

!!! note

Currently it is not possible for extensions written in Cython to declare
they support running without the GIL. Work is under way to add support
(see [cython#6242](https://github.com/cython/cython/pull/6242)).

C++ extension modules making use of `pybind11` can easily declare support for
running with the GIL disabled via the
[`gil_not_used`](https://pybind11.readthedocs.io/en/stable/reference.html#_CPPv4N7module_23create_extension_moduleEPKcPKcP10module_def16mod_gil_not_used)
argument to `create_extension_module`.

Starting with Cython 3.1.0 (only available via the nightly wheels), extension
modules written in Cython can also do so using the
[`freethreading_compatible`](https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html#compiler-directives)
compiler directive. It can be enabled either per module or globally by adding
`-Xfreethreading_comparible=True` to the Cython arguments via the project's
build system.

C or C++ extension modules using multi-phase initialization can specify the
[`Py_mod_gil`](https://docs.python.org/3.13/c-api/module.html#c.Py_mod_gil)
module slot like this:
Expand Down

0 comments on commit 2f787b9

Please sign in to comment.