Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[3.13] gh-137400: Fix thread-safety issues when profiling all threads (gh-137518)#137733

Merged
colesbury merged 6 commits intopython:3.13python/cpython:3.13from
colesbury:backport-a10152f-3.13colesbury/cpython:backport-a10152f-3.13Copy head branch name to clipboard
Oct 9, 2025
Merged

[3.13] gh-137400: Fix thread-safety issues when profiling all threads (gh-137518)#137733
colesbury merged 6 commits intopython:3.13python/cpython:3.13from
colesbury:backport-a10152f-3.13colesbury/cpython:backport-a10152f-3.13Copy head branch name to clipboard

Conversation

@colesbury
Copy link
Contributor

@colesbury colesbury commented Aug 13, 2025

There were a few thread-safety issues when profiling or tracing all threads via PyEval_SetProfileAllThreads or PyEval_SetTraceAllThreads:

  • The loop over thread states could crash if a thread exits concurrently (in both the free threading and default build)
  • The modification of c_profilefunc and c_tracefunc wasn't thread-safe on the free threading build. (cherry picked from commit a10152f)

…hreads (pythongh-137518)

There were a few thread-safety issues when profiling or tracing all
threads via PyEval_SetProfileAllThreads or PyEval_SetTraceAllThreads:

* The loop over thread states could crash if a thread exits concurrently
  (in both the free threading and default build)
* The modification of `c_profilefunc` and `c_tracefunc` wasn't
  thread-safe on the free threading build.
(cherry picked from commit a10152f)

Co-authored-by: Sam Gross <colesbury@gmail.com>
@Yhg1s
Copy link
Member

Yhg1s commented Aug 14, 2025

FYI, the ABI change seems fine to me.

self.set = not self.set


@threading_helper.requires_working_threading()
Copy link
Member

Choose a reason for hiding this comment

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

Presumably this test should work regardless of the threading model?
So, maybe just run this test unconditionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the InstrumentationMultiThreadedMixin subclasses hang on wasi where there are just no-op pthread stubs.

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

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

The backport looks good to me!

Though, given that 3.13t is experimental and 3.14 is now out, maybe we should start thinking about not doing backports like this any more...

@colesbury
Copy link
Contributor Author

Though, given that 3.13t is experimental and 3.14 is now out, maybe we should start thinking about not doing backports like this any more...

I generally agree, but one of the reasons I decided to backport this is that I think it will make the free-threaded CI more stable as well as fixing a thread-safety issue.

@colesbury colesbury merged commit 16d2e97 into python:3.13 Oct 9, 2025
81 of 83 checks passed
@colesbury colesbury deleted the backport-a10152f-3.13 branch October 9, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.