Skip to content

Conversation

@colesbury
Copy link
Contributor

@colesburycolesbury commented Mar 19, 2025

This makes more operations on frame objects thread-safe in the free threaded build, which fixes some data races that occurred when passing exceptions between threads.

However, accessing local variables or the line number of a frame from another thread while its still executing is not thread-safe and may crash the interpreter.

This makes more operations on frame objects thread-safe in the free threaded build, which fixes some data races that occurred when passing exceptions between threads. However, accessing local variables from another thread while its running is still not thread-safe and may crash the interpreter.
@colesburycolesbury marked this pull request as ready for review March 19, 2025 21:20
@colesbury
Copy link
ContributorAuthor

I added the additional critical sections, although I'm pretty ambivalent about having them in the C APIs.

Copy link
Contributor

@kumaraditya303kumaraditya303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@colesburycolesbury merged commit 4f32516 into python:mainMar 21, 2025
45 checks passed
@colesburycolesbury deleted the gh-128421-frame branch March 21, 2025 15:10
colesbury added a commit to colesbury/cpython that referenced this pull request Mar 25, 2025
The recent PR pythongh-131479 added locking to `take_ownership` in the free threading build. The cost is not really the locking -- that path isn't taken frequently -- but the inlined code causes extra register spills and slows down RETURN_VALUE, even when it's not taken. Mark `take_ownership` as `Py_NO_INLINE` to avoid the regression.
colesbury added a commit to colesbury/cpython that referenced this pull request Mar 25, 2025
The recent PR pythongh-131479 added locking to `take_ownership` in the free threading build. The cost is not really the locking -- that path isn't taken frequently -- but the inlined code causes extra register spills and slows down RETURN_VALUE, even when it's not taken. Mark `take_ownership` as `Py_NO_INLINE` to avoid the regression. Also limit locking in PyFrameObject to Python functions, not the C API.
colesbury added a commit to colesbury/cpython that referenced this pull request Mar 27, 2025
The recent PR pythongh-131479 added locking to `take_ownership` in the free threading build. The cost is not really the locking -- that path isn't taken frequently -- but the inlined code causes extra register spills and slows down RETURN_VALUE, even when it's not taken. Mark `take_ownership` as `Py_NO_INLINE` to avoid the regression. Also limit locking in PyFrameObject to Python functions, not the C API. PyFrame_GetCode is called frequently by coverage and tracing tools.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@colesbury@kumaraditya303