Skip to content

Conversation

@encukou
Copy link
Member

@encukou encukou commented Nov 20, 2025

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
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

🤖 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
Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

LGTM

@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
46 checks passed
@encukou encukou deleted the modexport-gil branch November 24, 2025 12:26
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.

3 participants