Title: `intern_static` is not thread-safe with multiple interpreters · Issue #122291 · python/cpython · GitHub
Open Graph Title: `intern_static` is not thread-safe with multiple interpreters · Issue #122291 · python/cpython
X Title: `intern_static` is not thread-safe with multiple interpreters · Issue #122291 · python/cpython
Description: Bug report Most static strings are interned during Python initialization in _PyUnicode_InitStaticStrings. However, the _Py_LATIN1_CHR characters (code points 0-255) are static, but not interned. They may be interned later while the Pytho...
Open Graph Description: Bug report Most static strings are interned during Python initialization in _PyUnicode_InitStaticStrings. However, the _Py_LATIN1_CHR characters (code points 0-255) are static, but not interned. Th...
X Description: Bug report Most static strings are interned during Python initialization in _PyUnicode_InitStaticStrings. However, the _Py_LATIN1_CHR characters (code points 0-255) are static, but not interned. Th...
Opengraph URL: https://github.com/python/cpython/issues/122291
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`intern_static` is not thread-safe with multiple interpreters","articleBody":"# Bug report\n\nMost static strings are interned during Python initialization in [`_PyUnicode_InitStaticStrings`](https://github.com/python/cpython/blob/5f6001130f8ada871193377954cfcfee01ef93b6/Include/internal/pycore_unicodeobject_generated.h). However, the `_Py_LATIN1_CHR` characters (code points 0-255) are static, but not interned. They may be interned later while the Python is running. This can happen for various reasons, including calls to `sys.intern`.\n\nThis isn't thread-safe: it modifies the hashtable `_PyRuntime.cached_objects.interned_strings`, which is shared across threads and interpreters, without any synchronization.\n\nIt also can break the interning identity invariant. You can have a non-static, interned 1-characters string later shadowed by the global interning of the static 1-character string.\n\n**Suggestions**\n\n* The `_PyRuntime.cached_objects.interned_strings` should be immutable. We should not modify it after `Py_Initialize()` until shutdown (i.e., `_PyUnicode_ClearInterned` called from `finalize_interp_types()`)\n* The 1-character latin1 strings should be interned. This can either be by explicitly interning them during startup, or by handling 1-character strings specially in `intern_common`.\n\ncc @encukou @ericsnowcurrently \n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-122303\n* gh-122347\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/colesbury","@type":"Person","name":"colesbury"},"datePublished":"2024-07-25T18:29:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/122291/cpython/issues/122291"}
| 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:ad422711-28da-00a5-78e8-a1fa683b6494 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8DF4:E8423:12EFDC1:195EAA5:696AD6EB |
| html-safe-nonce | 17e687c52961b67296565725c2b5baef6b70686647a0f66f53f4f8064f096992 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4REY0OkU4NDIzOjEyRUZEQzE6MTk1RUFBNTo2OTZBRDZFQiIsInZpc2l0b3JfaWQiOiI1MTEwMDU1ODUzMjE3MjA4MDQzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d270c042d75f49c8d83cfc68388ff7ad2301620ae8d99aa9ece62dba32229561 |
| hovercard-subject-tag | issue:2430734538 |
| 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/122291/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9465db5d221b4b6daf1c6ee4576b0a4aa74540f720659bffa9c7e3db5a263f4e/python/cpython/issues/122291 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9465db5d221b4b6daf1c6ee4576b0a4aa74540f720659bffa9c7e3db5a263f4e/python/cpython/issues/122291 |
| og:image:alt | Bug report Most static strings are interned during Python initialization in _PyUnicode_InitStaticStrings. However, the _Py_LATIN1_CHR characters (code points 0-255) are static, but not interned. Th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | colesbury |
| hostname | github.com |
| expected-hostname | github.com |
| None | c785f4ce187e9e7331257791b36ddee01625bb8e292a9b4fe2c16d4c006abf5d |
| 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 | c718a376fcf780eb22089171adb84a543f660bf7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width