-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
gh-125286: Bug fix for trace-refs logic and shared objects #125314
Conversation
The TSAN nogil build fails tests for me on the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little unclear on the change here. My understanding is that we don't want the interned strings on legacy subinterpreters to be tracked on those interpreter's refs. It seems to me like the change in this PR has stopped fixing that for each interpreter, which would put us back to where we were before. What am I missing?
Other than that, I have one small suggestion.
Objects/object.c
Outdated
PyInterpreterState *main_interp = _PyInterpreterState_Main(); | ||
if (interp != main_interp && | ||
interp->feature_flags & Py_RTFLAGS_USE_MAIN_OBMALLOC) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, you can also use _Py_IsMainInterpreter()
:
PyInterpreterState *main_interp = _PyInterpreterState_Main(); | |
if (interp != main_interp && | |
interp->feature_flags & Py_RTFLAGS_USE_MAIN_OBMALLOC) { | |
if (_Py_IsMainInterpreter(interp) && | |
interp->feature_flags & Py_RTFLAGS_USE_MAIN_OBMALLOC) { |
The case with shared objects (other than interned strings) can't seem to happen so comment that code out. Small code cleanups. Simplify the _testembed.c test, don't need a separate helper module.
A problem with trace refs occurs both with immortal and mortal interned strings. The previous fix, I was trying to trigger a third case, where objects other than interned strings are shared and are created in one interpreter and deallocated in a different one. That would cause
Fixed as you suggest. |
Maybe I overdid it with the comments, some are a bit redundant. Another idea I was toying with is to make this tracerefs cleanup logic active only if non-isolated interpreters are being used. You need a flag on the main interp to know if sub-interpreters have been used that share its interned string dict. Possible patch here: https://gist.github.com/nascheme/2243a137b9f9aa4639590231e3b8e004 It adds a new set of internal flags to the interp state so I think it can't be backported since it changes the ABI. I tried using |
I wonder: for interpreters that |
I think that could work and would simplify the code. The major impact would be that |
I think that the assumption so far of that call is to get all objects in existence. I don't think semantics have been defined after subinterpeters were introduced so we have some wiggle room here |
Here's a PR that shares the main refchain with all legacy interpreters: #125709. FWIW, they all used to share it when it was stored in global variables. |
Closing since GH-125709 fixes the same issue and seems a better approach. |
Fix the TraceRefs build to handle interned strings (both mortal and immortal) that are shared between interpreters.