Skip to content

gh-141780: Make PyModule_FromSlotsAndSpec enable GIL if needed - #141785

Merged
encukou merged 10 commits into
python:mainfrom
encukou:modexport-gil
Nov 24, 2025
Merged

encukou merged 10 commits into
python:mainfrom
encukou:modexport-gil

Conversation

@encukou

@encukou encukou commented Nov 20, 2025 •

Copy link
Copy Markdown
Member

We don't need to enable GIL for the PyModExport_ function, which is supposed to do as little as possible before returning a static array. Py_MOD_GIL_USED can be handled at module creation time, without enabling it transiently first.

The main difference from PyModuleDef (i.e. import.c's import_run_extension) is that he Py_mod_create function runs without the GIL enabled transiently. (It does run with GIL enabled permanently if Py_MOD_GIL_USED is specified -- same as the Py_mod_exec function, which always runs after the EnableGILTransient block.)

Also, if Py_mod_create makes a non-module object, Py_mod_gil is honored.

@colesbury, does this look OK?
(The first commit has the change; the next three 7 are tests/docs)

import tempfile
import types

_testsinglephase = import_helper.import_module("_testsinglephase")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_testsinglephase is unusable in subinterpreters.

@encukou
encukou marked this pull request as draft November 20, 2025 13:20
@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 20, 2025
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 5b8b87c 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F141785%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 20, 2025

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread Python/import.c Resolved
@brettcannon
brettcannon removed their request for review November 21, 2025 00:02
@encukou
encukou marked this pull request as ready for review November 21, 2025 15:08
Co-authored-by: Sam Gross <colesbury@gmail.com>
@encukou
encukou merged commit bf66bce into python:main Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants