-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
intern_static
is not thread-safe with multiple interpreters
#122291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Interning them makes sense. I'll send a PR. |
…-122303) (cherry picked from commit bb09ba6) Co-authored-by: Petr Viktorin <[email protected]>
FWIW:
Yup, that's a bug, so the fix should be backported.
Hmm, interning a short string should give you the static singleton. |
Before the PR for this issue we had: cpython/Objects/unicodeobject.c Lines 15480 to 15493 in c086962
|
…) (GH-122347) (cherry picked from commit bb09ba6) Co-authored-by: Petr Viktorin <[email protected]>
Looks like this has been fixed for a while. |
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 Python is running. This can happen for various reasons, including calls tosys.intern
.This isn't thread-safe: it modifies the hashtable
_PyRuntime.cached_objects.interned_strings
, which is shared across threads and interpreters, without any synchronization.It 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.
Suggestions
_PyRuntime.cached_objects.interned_strings
should be immutable. We should not modify it afterPy_Initialize()
until shutdown (i.e.,_PyUnicode_ClearInterned
called fromfinalize_interp_types()
)intern_common
.cc @encukou @ericsnowcurrently
Linked PRs
The text was updated successfully, but these errors were encountered: