gh-158364: Don't report other interpreters' threads in sys._current_f… - #158369
Conversation
Documentation build overview
|
|
Thanks for the review! Force-pushed with all of it addressed: Both versionchanged blocks are gone — Doc/library/sys.rst is untouched now. |
|
A thread only shows up in sys._current_exceptions() with something other |
f10e587 to
e05c195
Compare
…rent_frames() sys._current_frames() materialized a PyFrameObject for every thread of every interpreter. A frame object created for a thread of another interpreter belongs to that interpreter: it is stored in its _PyInterpreterFrame.frame_obj and deallocated when that interpreter pops the frame, while the calling interpreter holds the reference from the returned dict and drops it at some arbitrary later time. Since PEP 684 gives each interpreter its own obmalloc arenas, the block ends up being freed by a different interpreter than the one that allocated it, which corrupts the heap and typically aborts the process inside free(). sys._current_exceptions() has the same problem: it hands out references to exception objects owned by other interpreters. Both functions now only report the threads of the calling interpreter. This matches PyUnstable_DumpTracebackThreads() (used by faulthandler), which already only dumps the threads of one interpreter. As a consequence, only the current interpreter's world needs to be stopped.
e05c195 to
20ce55f
Compare
ZeroIntensity
left a comment
There was a problem hiding this comment.
LGTM, congrats on your first contribution!
|
Thanks @Himesh-rupchandani for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
GH-158471 is a backport of this pull request to the 3.15 branch. |
|
Sorry, @Himesh-rupchandani and @ZeroIntensity, I could not cleanly backport this to |
|
GH-158472 is a backport of this pull request to the 3.14 branch. |
|
GH-158473 is a backport of this pull request to the 3.13 branch. |
…sys._current_frames` (pythonGH-158369) (pythonGH-158472) (cherry picked from commit c3cb468) Co-authored-by: Himesh Rupchandani <rupchandanihimesh69@gmail.com>
…rames()
sys._current_frames() materialized a PyFrameObject for every thread of every interpreter. A frame object created for a thread of another interpreter belongs to that interpreter: it is stored in its _PyInterpreterFrame.frame_obj and deallocated when that interpreter pops the frame, while the calling interpreter holds the reference from the returned dict and drops it at some arbitrary later time. Since PEP 684 gives each interpreter its own obmalloc arenas, the block ends up being freed by a different interpreter than the one that allocated it, which corrupts the heap and typically aborts the process inside free().
sys._current_exceptions() has the same problem: it hands out references to exception objects owned by other interpreters.
Both functions now only report the threads of the calling interpreter. This matches PyUnstable_DumpTracebackThreads() (used by faulthandler), which already only dumps the threads of one interpreter. As a consequence, only the current interpreter's world needs to be stopped.