Skip to content

Allow C extensions to declare compatibility with free-threading #116322

Description

@swtaarrs

Feature or enhancement

There are a few pieces to this:

  1. Add a Py_mod_gil slot, as described in PEP 703, that multi-phase init modules can use to indicate that they support free-threading.
  2. Add a PyModule_ExperimentalSetGIL() function (discussed here) that single-phase init modules can use in place of Py_mod_gil.
  3. Mark all built-in modules as free-threading compatible with one of the above mechanisms.
  4. Enable the GIL while loading a C module and leave it permanently enabled if the module does not declare free-threading compatibility.

1-3 are addressed in gh-116882; 4 will be addressed in a separate PR.

Linked PRs

Activity

  1. self-assigned this
    on Mar 11, 2024
  2. swtaarrs commented on Mar 11, 2024

    @swtaarrs
    MemberAuthor

    What warning category should this issue? ImportWarning sounds like a good fit at first, but it's ignored by the default warning filters, which we don't want. Of the categories not ignored by default, RuntimeWarning seems like the best fit to me.

  3. changed the title [-]Implement `Py_mod_gil` slot for free-threading-safe extensions[/-] [+]Allow C extensions to declare compatibility with free-threading[/+] on May 2, 2024
  4. added a commit that references this issue on May 3, 2024
  5. added 2 commits that reference this issue on May 6, 2024
  6. added a commit that references this issue on May 7, 2024
  7. colesbury commented on May 7, 2024

    @colesbury
    Contributor

    @swtaarrs is this finished now?

  8. swtaarrs commented on May 7, 2024

    @swtaarrs
    MemberAuthor

    Yep!

  9. added 3 commits that reference this issue on May 8, 2024
  10. added a commit that references this issue on Jul 25, 2024
  11. added a commit that references this issue on Jul 25, 2024
  12. added a commit that references this issue on Jul 25, 2024
  13. added a commit that references this issue on Jul 25, 2024
  14. danielivascsenko2-ux commented on Aug 22, 2025

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions