From e702061ca9015612672cd0059a8db49f2e97f78a Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Mon, 15 Jul 2024 13:53:24 +0200 Subject: [PATCH 1/3] ENH: Globally enable Cython free-threading directive This is the Cython equivalent of adding a `Py_mod_gil` slot with `Py_MOD_GIL_NOT_USED` like we did in #59135. --- meson.build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/meson.build b/meson.build index 06623a305ab54..88f3ceb7e86eb 100644 --- a/meson.build +++ b/meson.build @@ -44,6 +44,11 @@ else meson.add_dist_script(py, versioneer, '-o', '_version_meson.py') endif +cy = meson.get_compiler('cython') +if cy.version().version_compare('>=3.1.0') + add_global_arguments('-Xfreethreading_compatible=true', language : 'cython') +endif + # Needed by pandas.test() when it looks for the pytest ini options py.install_sources( 'pyproject.toml', From 4363dc34a9c99edbfaedf8ede0c4907eb6e996da Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Tue, 16 Jul 2024 13:32:31 +0200 Subject: [PATCH 2/3] Use add_project_arguments --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 88f3ceb7e86eb..efe543b7a267c 100644 --- a/meson.build +++ b/meson.build @@ -46,7 +46,7 @@ endif cy = meson.get_compiler('cython') if cy.version().version_compare('>=3.1.0') - add_global_arguments('-Xfreethreading_compatible=true', language : 'cython') + add_project_arguments('-Xfreethreading_compatible=true', language : 'cython') endif # Needed by pandas.test() when it looks for the pytest ini options From 424d56f69631e7c978a2f50693291d9fe25e7f13 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Tue, 16 Jul 2024 14:09:17 +0200 Subject: [PATCH 3/3] Mark json with Py_MOD_GIL_NOT_USED & remove PYTHON_GIL env var from ci test job --- .github/workflows/unit-tests.yml | 2 -- pandas/_libs/src/vendored/ujson/python/ujson.c | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index ddb6ecbe83126..a9585c17454fb 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -388,8 +388,6 @@ jobs: - name: Run Tests uses: ./.github/actions/run-tests - env: - PYTHON_GIL: 0 # NOTE: this job must be kept in sync with the Pyodide build job in wheels.yml emscripten: diff --git a/pandas/_libs/src/vendored/ujson/python/ujson.c b/pandas/_libs/src/vendored/ujson/python/ujson.c index 075411a23b075..f369d122a3dbe 100644 --- a/pandas/_libs/src/vendored/ujson/python/ujson.c +++ b/pandas/_libs/src/vendored/ujson/python/ujson.c @@ -384,6 +384,10 @@ PyMODINIT_FUNC PyInit_json(void) { return NULL; } +#ifdef Py_GIL_DISABLED + PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED); +#endif + #ifndef PYPY_VERSION PyObject *mod_decimal = PyImport_ImportModule("decimal"); if (mod_decimal) {