Title: Python 3.13 breaks circular imports through single-phase extension modules using non-isolated subinterpreters · Issue #138045 · python/cpython · GitHub
Open Graph Title: Python 3.13 breaks circular imports through single-phase extension modules using non-isolated subinterpreters · Issue #138045 · python/cpython
X Title: Python 3.13 breaks circular imports through single-phase extension modules using non-isolated subinterpreters · Issue #138045 · python/cpython
Description: Bug report Bug description: I believe this regression was caused by the changes made to fix gh-117953. Repro: import _interpreters interp = _interpreters.create() _interpreters.run_string(interp, "import numpy") Tested on Fedora 41 with ...
Open Graph Description: Bug report Bug description: I believe this regression was caused by the changes made to fix gh-117953. Repro: import _interpreters interp = _interpreters.create() _interpreters.run_string(interp, "...
X Description: Bug report Bug description: I believe this regression was caused by the changes made to fix gh-117953. Repro: import _interpreters interp = _interpreters.create() _interpreters.run_string(interp, &...
Opengraph URL: https://github.com/python/cpython/issues/138045
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Python 3.13 breaks circular imports through single-phase extension modules using non-isolated subinterpreters","articleBody":"# Bug report\n\n### Bug description:\n\nI believe this regression was caused by the changes made to fix gh-117953.\n\nRepro:\n```python\nimport _interpreters\ninterp = _interpreters.create()\n_interpreters.run_string(interp, \"import numpy\")\n```\n\nTested on Fedora 41 with Python 3.13.5 and numpy 1.26.4, and Fedora 42 with 3.13.7 and 2.2.6, respectively.\n\nWhat happens is that:\n* The subinterpreter tries to load `numpy`\n* Numpy loads a bunch of Python modules\n* numpy eventually tries to load the `multiarray` extension\n* import_run_extension switches to the main interpreter, as explained in the comment\n* The module init is called in the main interpreter\n* PyInit__multiarray_umath actually initializes in the main interpreter\n* initialize_static_globals() attempts to load some numpy Python modules from inside the extension\n* Since these modules aren't loaded in the main interpreter yet, the whole process starts over again loading `numpy`, now in the main interpreter\n* This then leads to loading the `multiarray` extension *again*, this time already in the main interpreter, so no switching happens\n* Python *reentrantly* attempts to initialize the (single-phase!) extension module in the main interpreter again\n* Kaboom\n\nThe easiest way to see the carnage in action is to run it under gdb and break on `PyInit__multiarray_umath`. You'll see it gets called twice, the second time reentrantly (with a 276-frame backtrace going through numpy initialization twice). If you don't set any breakpoints, you'll get crashes trying to process exceptions and other craziness when the original reentrant execution backtrace is long gone.\n\nnumpy does not support subinterpreters, but I would expect it to work when it is used in a single subinterpreter without isolation.\n\nThis is the root cause for:\n* https://tracker.ceph.com/issues/67696\n* https://bugzilla.redhat.com/show_bug.cgi?id=2307587\n\n\n### CPython versions tested on:\n\n3.13\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-142979\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/marcan","@type":"Person","name":"marcan"},"datePublished":"2025-08-22T08:23:59Z","url":"https://github.com/python/cpython/issues/138045"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:32f5c993-525b-5b7b-7294-e4c101150e66 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D60C:1C3DC0:9335D3:C4D211:6B004223 |
| html-safe-nonce | 742f855020a67d411b88ca06f800ec675ce132063f35a916709403a7f01ef0f3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENjBDOjFDM0RDMDo5MzM1RDM6QzREMjExOjZCMDA0MjIzIiwidmlzaXRvcl9pZCI6IjgwODM1ODE5NDk4NzQwMjkwOTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c17a3e9cdb9aab86c674512b1289d111c5c254cec91cc3046241727be8a64a1b |
| hovercard-subject-tag | issue:3344623987 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/138045/issue_layout |
| twitter:image | https://opengraph.githubassets.com/67b1c6b63232620f9ef18e4f325c96e0997298556f1d39e4265ad32bd2cddf18/python/cpython/issues/138045 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/67b1c6b63232620f9ef18e4f325c96e0997298556f1d39e4265ad32bd2cddf18/python/cpython/issues/138045 |
| og:image:alt | Bug report Bug description: I believe this regression was caused by the changes made to fix gh-117953. Repro: import _interpreters interp = _interpreters.create() _interpreters.run_string(interp, "... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | marcan |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width