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 — gh-141780: Make PyModule_FromSlotsAndSpec enable GIL if needed by encukou · Pull Request #141785 · python/cpython

Conversation

@encukou

@encukou encukou commented Nov 20, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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)

  • Issue: Forcing enabling the GIL doesn't seem to work with PEP 793 initialization #141780

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
encukou added 4 commits November 20, 2025 11:23
@encukou
pythongh-141780: Make PyModule_FromSlotsAndSpec enable GIL if needed
13faf0f
@encukou
Make test.test_importlib and _testmultiphase importable in subinterpr…
60a669c
…eters
@encukou
Test that Py_MOD_GIL_USED re-enables the GIL
8a8a344
@encukou
blurb
e2c9c7e
@encukou
encukou requested review from brettcannon, ericsnowcurrently, kumaraditya303, ncoghlan and warsaw as code owners November 20, 2025 12:38
@bedevere-app bedevere-app Bot added the awaiting core review label Nov 20, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Nov 20, 2025
Forcing enabling the GIL doesn't seem to work with PEP 793 initialization #141780
Closed
encukou
encukou commented Nov 20, 2025
View reviewed changes
Comment thread Lib/test/test_importlib/util.py
import tempfile
import types

_testsinglephase = import_helper.import_module("_testsinglephase")

@encukou encukou Nov 20, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@encukou
encukou marked this pull request as draft November 20, 2025 13:20
@bedevere-app bedevere-app Bot removed the awaiting core review label Nov 20, 2025
encukou added 5 commits November 20, 2025 14:24
@encukou
Pass with -Werror
b18c679
@encukou
Skip test_from_modexport_empty_slots on GIL-ful builds
103f427
@encukou
Use @requires_subinterpreters
91d59e9
@encukou
Add more gil & interpreters slots
3e82c25
@encukou
Fix assertion logic
5b8b87c
@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 20, 2025
@bedevere-bot

bedevere-bot commented Nov 20, 2025

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/import.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the awaiting merge label Nov 20, 2025
@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
@bedevere-app bedevere-app Bot added awaiting core review and removed awaiting merge labels Nov 21, 2025
@encukou @colesbury
Python/import.c: PEP7
cde6c25
Co-authored-by: Sam Gross <[email protected]>
@encukou
encukou merged commit bf66bce into python:main Nov 24, 2025
46 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Nov 24, 2025
@encukou
encukou deleted the modexport-gil branch November 24, 2025 12:26
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@encukou @StanFromIreland
pythongh-141780: Make PyModule_FromSlotsAndSpec enable GIL if needed (…
f614d18
…pythonGH-141785)
ashm-dev pushed a commit to ashm-dev/cpython that referenced this pull request Dec 8, 2025
@encukou @ashm-dev
pythongh-141780: Make PyModule_FromSlotsAndSpec enable GIL if needed (…
1fdf8af
…pythonGH-141785)
This was referenced Feb 11, 2026
[3.14] gh-144601: Avoid sharing exception objects raised in a PyInit function across multiple interpreters (GH-144602) #144633
Merged
[3.14] gh-144601: Use _testmultiphase instead of _testsinglephase in test_importlib #144769
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@colesbury colesbury colesbury approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner
@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303 kumaraditya303 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@encukou @bedevere-bot @colesbury
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.