For free-threaded CPython (xref PEP 703, https://py-free-threading.github.io/), Pythran seems to be working quite well already. We've tested Pythran-generated extension modules reasonably well within SciPy now with GIL-free multi-threaded tests, and so far everything looks healthy. There is one thing to do in Pythran though, namely adding a compile option to allow the user to request that the extension module is marked as compatible with free-threading.
That is pretty straightforward, it looks like this (see https://py-free-threading.github.io/porting/#declaring-free-threaded-support):
static PyModuleDef_Slot module_slots[] = {
...
#ifdef Py_GIL_DISABLED
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
#endif
or for single-phase initialization:
PyMODINIT_FUNC
PyInit__module(void)
{
...
#ifdef Py_GIL_DISABLED
PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED);
#endif
The way this is done in Cython and numpy.f2py is similar, with an opt-in flag to cython and f2py:
For Pythran I'd propose the same, an opt-in flag that when given inserts one of the #ifdef Py_GIL_DISABLED snippets in the generated C++ code:
pythran --freethreading-compatible
For free-threaded CPython (xref PEP 703, https://py-free-threading.github.io/), Pythran seems to be working quite well already. We've tested Pythran-generated extension modules reasonably well within SciPy now with GIL-free multi-threaded tests, and so far everything looks healthy. There is one thing to do in Pythran though, namely adding a compile option to allow the user to request that the extension module is marked as compatible with free-threading.
That is pretty straightforward, it looks like this (see https://py-free-threading.github.io/porting/#declaring-free-threaded-support):
or for single-phase initialization:
The way this is done in Cython and
numpy.f2pyis similar, with an opt-in flag tocythonandf2py:cython -Xfreethreading_compatible=True(xref Add freethreading_compatible directive to set Py_mod_gil slot cython/cython#6242)f2py --freethreading-compatible(xref https://github.com/numpy/numpy/pull/26981/files)For Pythran I'd propose the same, an opt-in flag that when given inserts one of the
#ifdef Py_GIL_DISABLEDsnippets in the generated C++ code: