Skip to content

gh-138045: Fix importing numpy in legacy subinterpreters by skipping switch to main interpreter when not needed - #142979

Closed
jan-hasse wants to merge 1 commit into
python:mainfrom
jan-hasse:fix-issue-138045
Closed

gh-138045: Fix importing numpy in legacy subinterpreters by skipping switch to main interpreter when not needed#142979
jan-hasse wants to merge 1 commit into
python:mainfrom
jan-hasse:fix-issue-138045

Conversation

@jan-hasse

@jan-hassejan-hasse commented Dec 19, 2025

Copy link
Copy Markdown

(singlephase == NULL) check in update_global_state_for_extension could be removed because it's only called with pointers to stack objects.

I've tried creating a minimal working reproducer instead of importing numpy with the example from #138045 (comment) but didn't manage to integrate that into Python's test suite. Maybe someone else has more knowledge on how to create a simple test that reproduce the numpy situation.

The fix can be backported down to 3.13.

@python-cla-bot

python-cla-botBot commented Dec 19, 2025

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@ZeroIntensityZeroIntensity left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a news entry, and ideally a test case. This seems difficult to test, though. You could look into adding something to _testsinglephase.

@brettcannon
brettcannon removed their request for review December 19, 2025 18:18
@kumaraditya303
kumaraditya303 removed their request for review December 29, 2025 11:40
…pping switch to main interpreter when not needed
(singlephase == NULL) check in update_global_state_for_extension could be removed because it's only called with pointers to stack objects.
@jan-hasse

Copy link
Copy Markdown
Author

Added a news entry. I was not able to implement a test, I already looked at _testsinglephase but wasn't able to setup something similar to numpy :(

@ZeroIntensity

Copy link
Copy Markdown
Member

Thanks for the contribution. See my comment -- this was already fixed by #144602.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@jan-hasse@ZeroIntensity