Skip to content

feat: enable free-threading builds#480

Merged
beckermr merged 5 commits into
masterfrom
freebird
Dec 9, 2025
Merged

feat: enable free-threading builds#480
beckermr merged 5 commits into
masterfrom
freebird

Conversation

@beckermr

@beckermr beckermr commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator

This PR enables python free-threading builds and add tests for them.

The changes here mean that the package won't reenable the GIL when imported.

However, there are some important limitations that are fundamental:

  • cfitsio does not support more than one thread using a given file pointer. Thus fitsio won't have support either. As usual with file-related potential race conditions, we leave this to the user to manage.

  • Even in free-threaded python, a you have to call the functions that detach the thread state in order to get performance gains for blocking i/o operations, etc. See this bit in the python manual (https://docs.python.org/3/c-api/init.html#thread-state-and-the-global-interpreter-lock)

    For free-threaded builds, the GIL is normally out of the question, but detaching the thread state is still required for blocking I/O and long operations.

    So confusingly, we still need to "release the GIL" per feat: release the GIL very minimally #476 even in a free-threaded build. For this PR, I am punting on this task to a future PRs.

Edit: The code snippet below does not work. I have another solution in another PR, but we can punt for now.

We could use the ideas here to raise errors on concurrent use of FITS objects from more than one thread. I will leave this to a potential future PR if we think it is worth the complexity.

@beckermr beckermr marked this pull request as ready for review December 9, 2025 18:12
@beckermr beckermr requested a review from esheldon December 9, 2025 18:12
@beckermr

beckermr commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator Author

@esheldon this one is ready for review!

@beckermr beckermr merged commit ceaeb81 into master Dec 9, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants