Skip to content

Commit

Permalink
GH-43536: [Python] Declare support for free-threading in Cython (#43606)
Browse files Browse the repository at this point in the history
### Rationale for this change

This is done by passing an extra flag when building the Cython extension modules. It is needed so that the GIL is not dynamically reenabled when importing `pyarrow.lib`.

### What changes are included in this PR?

Changes to CMake so that the extra flag is passed when building Cython extension modules.

* GitHub Issue: #43536

Lead-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
lysnikolaou and kou authored Aug 13, 2024
1 parent 483bc7b commit e8e9d1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cpp/cmake_modules/UseCython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,9 @@ function(cython_add_module _name pyx_target_name generated_files)
add_dependencies(${_name} ${pyx_target_name})
endfunction()

execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from Cython.Compiler.Version import version; print(version)"
OUTPUT_VARIABLE CYTHON_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CYTHON_VERSION "${CYTHON_VERSION_OUTPUT}")

include(CMakeParseArguments)
5 changes: 5 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ message(STATUS "Found NumPy version: ${Python3_NumPy_VERSION}")
message(STATUS "NumPy include dir: ${NUMPY_INCLUDE_DIRS}")

include(UseCython)
message(STATUS "Found Cython version: ${CYTHON_VERSION}")

# Arrow C++ and set default PyArrow build options
include(GNUInstallDirs)
Expand Down Expand Up @@ -855,6 +856,10 @@ set(CYTHON_FLAGS "${CYTHON_FLAGS}" "--warning-errors")
# undocumented Cython feature.
set(CYTHON_FLAGS "${CYTHON_FLAGS}" "--no-c-in-traceback")

if(CYTHON_VERSION VERSION_GREATER_EQUAL "3.1.0a0")
list(APPEND CYTHON_FLAGS "-Xfreethreading_compatible=True")
endif()

foreach(module ${CYTHON_EXTENSIONS})
string(REPLACE "." ";" directories ${module})
list(GET directories -1 module_name)
Expand Down

0 comments on commit e8e9d1a

Please sign in to comment.