cpython icon indicating copy to clipboard operation
cpython copied to clipboard

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

Open jan-hasse opened this issue 3 weeks ago • 3 comments

(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 https://github.com/python/cpython/issues/138045#issuecomment-3216214055 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.

  • Issue: gh-138045

jan-hasse avatar Dec 19 '25 14:12 jan-hasse

All commit authors signed the Contributor License Agreement.

CLA signed

python-cla-bot[bot] avatar Dec 19 '25 14:12 python-cla-bot[bot]

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.

bedevere-app[bot] avatar Dec 19 '25 14:12 bedevere-app[bot]

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

jan-hasse avatar Jan 02 '26 09:01 jan-hasse