Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Use multi-phase initialisation (PEP 489) for extension modules #29021

Open
@AA-Turner

Description

@AA-Turner

Proposed new feature or change:

This is intended to be a tracking issue for a series of PRs I will shortly submit.

Multi-phase initialisation was introduced inPEP 489 for Python 3.5. It replaces the previous 'single-phase' mechanism by splitting the module creation process into creation and execution phases. Quoting fromthe documentation:

Extension modules created this way behave more like Python modules: the initialization is split between the creation phase, when the module object is created, and the execution phase, when it is populated. The distinction is similar to the__new__() and__init__() methods of classes.

This is also the stable mechanism to declare compatibility with both free-threading and subinterpreters (though note thatthis PR does not attempt to add support for subinterpreters).

A common point of confusion/conflation is multi-phase initialisation and module isolation. As noted on thePython Discourse forum, "Implementing extension module isolation is a very good thing, but if a module uses static types or (C) global variables then the effort to isolate becomes non-trivial.". This issue only seeks to implement multi-phase initialisation, generally following the guide that Eric set out in that thread:

  1. move the content of the module’s init function to a corresponding “module exec” function (dropping the call to create the module object)
  2. set the module def’sm_slots field to an array with:
  • aPy_mod_exec slot, set to the new module exec function
  • aPy_mod_multiple_interpreters slot, set toPy_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED
  • to try free-threading, aPy_mod_gil slot, set toPy_MOD_GIL_NOT_USED
  1. setdef.m_size to 0 (if negative)
  2. update the module init function to onlyreturn PyModuleDef_Init(def); for the corresponding module def

cc@ngoldbaum

xref:

A

PRs:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp