GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add a mechanism for single-phase init modules to declare free-threading compatibility · Issue #117526 · python/cpython

Add a mechanism for single-phase init modules to declare free-threading compatibility #117526

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Add a mechanism for single-phase init modules to declare free-threading compatibility#117526
Copy link
Assignees
swtaarrs
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@swtaarrs
swtaarrs
opened on Apr 3, 2024
Issue body actions

Feature or enhancement

Proposal:

gh-116322 only works for modules using multi-phase init; we need an alternative mechanism for for single-phase init modules since they can't provide m_slots.

We originally considered indicating compatibility in the symbol table of the .so containing the module, either by the presence of a magic symbol, or by providing an alternate init function with a PyInitT_ prefix. As pointed out by @Yhg1s in Discord, that solution doesn't work with modules added to inittab.

The current proposal is:

  • Before calling any module init function, enable the GIL if it is disabled (this will most likely be done as part of gh-116322: Add Py_mod_gil module slot #116882).
  • In free-threaded builds, add a void *md_gil member to PyModuleObject. It defaults to Py_MOD_GIL_USED (the same constant from Allow C extensions to declare compatibility with free-threading #116322).
  • Introduce a new public C API function PyModule_SetGIL(PyObject *mod, void *gil). If a single-phase init module can run without the GIL, it will call PyModule_SetGIL(mod, Py_MOD_GIL_NOT_USED) in its init function. This function will be a no-op in normal builds, and will set md_gil to its argument in free-threaded builds.
  • After the init function returns, if the module's md_gil member is set to Py_MOD_GIL_NOT_USED and the GIL was disabled before calling the init function, disable the GIL.

Activity

  1. swtaarrs
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-free-threading
    on Apr 3, 2024
  2. Eclips4
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Apr 4, 2024
  3. swtaarrs
    self-assigned this
    on Apr 5, 2024
  4. swtaarrs commented on May 2, 2024

    @swtaarrs
    swtaarrs
    on May 2, 2024
    MemberAuthor
    More actions

    Closing this to consolidate in gh-116322 (there has also been some relevant discussion in this thread).

  5. swtaarrs
    closed this as completedon May 2, 2024
  6. swtaarrs
    closed this as not plannedon May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @swtaarrs
    swtaarrs

Labels

extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.