GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-128421: Add locking to most frame object functions by colesbury · Pull Request #131479 · python/cpython

Conversation

@colesbury

@colesbury colesbury commented Mar 19, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

  • Issue: data races in frame inspection and tracebacks #128421

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot mentioned this pull request Mar 19, 2025
data races in frame inspection and tracebacks #128421
Closed
@colesbury colesbury added skip news topic-free-threading labels Mar 19, 2025
@colesbury
pythongh-128421: Add locking to most frame object functions
c6f3c86
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.
@colesbury
colesbury force-pushed the gh-128421-frame branch from 44f8c85 to c6f3c86 Compare March 19, 2025 20:41
@colesbury
colesbury marked this pull request as ready for review March 19, 2025 21:20
@colesbury
colesbury requested a review from markshannon as a code owner March 19, 2025 21:20
@bedevere-app bedevere-app Bot added the awaiting core review label Mar 19, 2025
@colesbury
colesbury requested a review from kumaraditya303 March 19, 2025 21:20
kumaraditya303
kumaraditya303 reviewed Mar 20, 2025
View reviewed changes
Comment thread Objects/frameobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Mar 20, 2025
View reviewed changes
Comment thread Objects/frameobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Mar 20, 2025
View reviewed changes
Comment thread Objects/frameobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Mar 20, 2025
View reviewed changes
Comment thread Objects/frameobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Mar 20, 2025
View reviewed changes
Comment thread Objects/frameobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@colesbury
Add missing critical sections
e404ece
@colesbury
colesbury requested a review from kumaraditya303 March 20, 2025 17:21
@colesbury
Fix warnings
045b98c
kumaraditya303
kumaraditya303 reviewed Mar 21, 2025
View reviewed changes
Comment thread Objects/frameobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Mar 21, 2025
View reviewed changes
Comment thread Objects/frameobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Mar 21, 2025
View reviewed changes
Comment thread Objects/frameobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 reviewed Mar 21, 2025
View reviewed changes
Comment thread Objects/frameobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@colesbury
Add additional locks
3cd5cf4
@colesbury

colesbury commented Mar 21, 2025

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

colesbury added 2 commits March 21, 2025 10:29
@colesbury
Merge branch 'main' into pythongh-128421-frame
676d639
@colesbury
Fix warning
b706936
kumaraditya303
kumaraditya303 approved these changes Mar 21, 2025
View reviewed changes

@kumaraditya303 kumaraditya303 left a comment

Copy link
Copy Markdown
Contributor

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.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Mar 21, 2025
@colesbury
colesbury merged commit 4f32516 into python:main Mar 21, 2025
@colesbury
colesbury deleted the gh-128421-frame branch March 21, 2025 15:10
@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 21, 2025
colesbury added a commit to colesbury/cpython that referenced this pull request Mar 25, 2025
@colesbury
pythongh-128421: Fix performance regerssion from adding locks to frames
ae7f6ab
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
@colesbury
pythongh-128421: Fix performance regerssion from adding locks to frames
80e36d7
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
@colesbury
pythongh-128421: Fix performance regeression from adding locks to frames
9414d6c
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.
@kumaraditya303 kumaraditya303 mentioned this pull request Jul 3, 2025
gh-117657: Make frame clearing thread-safe #120542
Closed
@colesbury colesbury mentioned this pull request Nov 26, 2025
Crash when inspecting frame of other thread in free-threaded build #118680
Closed
@brijkapadia brijkapadia mentioned this pull request Jul 16, 2026
Free-threaded build: reading a sys._current_frames() frame is a use-after-free #152355
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news topic-free-threading

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@colesbury @kumaraditya303
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.