Skip to content

ENH: stats: enable free-threading support for Cython extensions #20267

Open

Description

@giusesorrentino

What is the problem this feature will solve?

Adding the module-level directive # cython: freethreading_compatible = True to astropy.stats._stats (assuming it is thread-safe) allows Astropy to run on free-threaded Python builds without re-enabling the GIL.

Currently, when running tests on a free-threaded Python build (verified on Python 3.15t), importing this module causes pytest to emit the following warning:

RuntimeWarning: The global interpreter lock (GIL) has been enabled to load module 'astropy.stats._stats', which has not declared that it can run safely without the GIL. To override this behavior and keep the GIL disabled (at your own risk), run with PYTHON_GIL=0 or -Xgil=0.

Describe the desired outcome

Add # cython: freethreading_compatible = True to astropy.stats._stats (and potentially other Cython modules if applicable) so that the module can be imported in free-threaded Python without automatically re-enabling the GIL.

Additional context

No response

Activity

  1. pllim commented on Aug 24, 2026

    @pllim
    Member

    This might be part of a larger issue at #16916

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions