Title: PyThreadState Sometimes Used for Different Threads for Subinterpreters · Issue #109860 · python/cpython · GitHub
Open Graph Title: PyThreadState Sometimes Used for Different Threads for Subinterpreters · Issue #109860 · python/cpython
X Title: PyThreadState Sometimes Used for Different Threads for Subinterpreters · Issue #109860 · python/cpython
Description: Bug report In a few places, we treat PyInterpreterState.threads.head (AKA PyInterpreterState_ThreadHead()) for subinterpreters as an unused thread state that we can use in a one-off manner: _PyInterpreterState_IDDecref() (Python/pystate....
Open Graph Description: Bug report In a few places, we treat PyInterpreterState.threads.head (AKA PyInterpreterState_ThreadHead()) for subinterpreters as an unused thread state that we can use in a one-off manner: _PyInte...
X Description: Bug report In a few places, we treat PyInterpreterState.threads.head (AKA PyInterpreterState_ThreadHead()) for subinterpreters as an unused thread state that we can use in a one-off manner: _PyInte...
Opengraph URL: https://github.com/python/cpython/issues/109860
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PyThreadState Sometimes Used for Different Threads for Subinterpreters ","articleBody":"# Bug report\n\nIn a few places, we treat `PyInterpreterState.threads.head` (AKA `PyInterpreterState_ThreadHead()`) for subinterpreters as an unused thread state that we can use in a one-off manner:\n\n* `_PyInterpreterState_IDDecref()` (Python/pystate.c)\n* `_call_in_interpreter()` (Python/pystate.c) - fixed in 3.13+ (gh-109556)\n* `_run_script_in_interpreter()` (Modules/_xxsubinterpreter.c)\n* `interp_destroy()` (Modules/_xxsubinterpreter.c)\n\nThe problem is that each thread state should correspond to a single OS thread, and for each OS thread there should be at most one thread state per interpreter. Using `PyInterpreterState.threads.head` like that violates those assumptions, which can cause problems. [^1]\n\n[^1]: Currently, this mostly doesn't affect the main interpreter. Ideally, the main interpreter wouldn't actually be treated specially. See gh-109857.\n\nAlso, some code assumes `PyInterpreterState.threads.head` is the current thread state, when it might not be:\n\n* `interpreter_clear()` (Python/pystate.c)\n* ...\n\nWe should fix this by always using the thread state that corresponds to the current thread (and create one if missing). For efficiency, we can use a thread-local (via `PyThread_tss_*`) to store each interpreter's thread state for that thread.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-110245\n* gh-110709\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ericsnowcurrently","@type":"Person","name":"ericsnowcurrently"},"datePublished":"2023-09-25T17:08:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/109860/cpython/issues/109860"}
| 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:9d8fc68f-bf78-d71a-abce-ea749fddefe8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 994A:2BBD61:29EF3AD:3745874:696B29DB |
| html-safe-nonce | 4d350b909d0809d12d6ac0ba84dd8aaa96a844a74afa49b6a62d60277bc1ce83 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OTRBOjJCQkQ2MToyOUVGM0FEOjM3NDU4NzQ6Njk2QjI5REIiLCJ2aXNpdG9yX2lkIjoiMTk2NTEyNDEyNzI2OTAwNTc4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 49bb09e4b9fb7a164637bb57ddd53a53da04b0217744ab683fa7e58e7e7cb26b |
| hovercard-subject-tag | issue:1911947964 |
| 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/109860/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d1b6afd4dfa13b33f200ce3b6eb7d1192382a42a7a0d817e4c9993c787a47d68/python/cpython/issues/109860 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d1b6afd4dfa13b33f200ce3b6eb7d1192382a42a7a0d817e4c9993c787a47d68/python/cpython/issues/109860 |
| og:image:alt | Bug report In a few places, we treat PyInterpreterState.threads.head (AKA PyInterpreterState_ThreadHead()) for subinterpreters as an unused thread state that we can use in a one-off manner: _PyInte... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ericsnowcurrently |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| 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 | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width