Title: An interpreter can start running during `_interpreters.destroy` · Issue #127041 · python/cpython · GitHub
Open Graph Title: An interpreter can start running during `_interpreters.destroy` · Issue #127041 · python/cpython
X Title: An interpreter can start running during `_interpreters.destroy` · Issue #127041 · python/cpython
Description: Crash report What happened? Now that gh-126914 is out of the way, we can try and deal with some of the other issues related to multithreading and subinterpreters that couldn't get dealt with before. Namely, the is_running_main inside _in...
Open Graph Description: Crash report What happened? Now that gh-126914 is out of the way, we can try and deal with some of the other issues related to multithreading and subinterpreters that couldn't get dealt with before...
X Description: Crash report What happened? Now that gh-126914 is out of the way, we can try and deal with some of the other issues related to multithreading and subinterpreters that couldn't get dealt with be...
Opengraph URL: https://github.com/python/cpython/issues/127041
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"An interpreter can start running during `_interpreters.destroy`","articleBody":"# Crash report\n\n### What happened?\n\nNow that gh-126914 is out of the way, we can try and deal with some of the other issues related to multithreading and subinterpreters that couldn't get dealt with before. Namely, the `is_running_main` inside `_interpreters.destroy` doesn't account for the fact that the interpreter could start running again by another thread *after* that check has already passed.\n\nQuick reproducer:\n\n```python\nfrom threading import Thread\nimport _interpreters\n\ninterp = _interpreters.create()\n\n\ndef run():\n _interpreters.run_string(interp, \"1\")\n _interpreters.destroy(interp)\n\n\nthreads = [Thread(target=run) for _ in range(1000)]\nfor thread in threads:\n thread.start()\n\nfor thread in threads:\n thread.join()\n```\n\nI think the simplest fix would be to just disallow a subinterpreter from ever set \"running main\" again after that check has finished. I implemented this already in the (closed) gh-126696, but I'd like to try and refactor that a bit before just copying things over to a new PR.\n\ncc @ericsnowcurrently, let me know if you have a better approach.\n\n### CPython versions tested on:\n\n3.13, 3.14, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-127044\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ZeroIntensity","@type":"Person","name":"ZeroIntensity"},"datePublished":"2024-11-19T21:21:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/127041/cpython/issues/127041"}
| 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:15a2ed17-1829-46b8-1a36-59ad76812a6c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9042:37F578:50CD913:71C0F9B:6A5703C3 |
| html-safe-nonce | c43db58b7adb11d52706335ee72c0410de5a5da35935d3f309e555d9e6cbcdbe |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDQyOjM3RjU3ODo1MENEOTEzOjcxQzBGOUI6NkE1NzAzQzMiLCJ2aXNpdG9yX2lkIjoiNTA3NzA5NDEyNjcxOTUzNDAxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 32c1085851d6df674eb2e1d41fbcbd5cbe3bf4add8093a11613f410bc93cb5fc |
| hovercard-subject-tag | issue:2673569711 |
| 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/127041/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f027501eff8a35511057242223aaa799378889db229c6f152c7b07b95effecf0/python/cpython/issues/127041 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f027501eff8a35511057242223aaa799378889db229c6f152c7b07b95effecf0/python/cpython/issues/127041 |
| og:image:alt | Crash report What happened? Now that gh-126914 is out of the way, we can try and deal with some of the other issues related to multithreading and subinterpreters that couldn't get dealt with before... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ZeroIntensity |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb29e5f807bd95e41196adfbc6d28f9af12d89830d8b684f3e871774ddff2fc |
| 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 | b056788a129fb0194b61f2ebb4c43f6a9f4dfd27 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width