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-137109: refactor warning about threads when forking (GH-141438) (GH-141614)#141639

Merged
gpshead merged 1 commit intopython:3.13python/cpython:3.13from
miss-islington:backport-0d8fb0b-3.13miss-islington/cpython:backport-0d8fb0b-3.13Copy head branch name to clipboard
Nov 17, 2025
Merged

[3.13] gh-137109: refactor warning about threads when forking (GH-141438) (GH-141614)#141639
gpshead merged 1 commit intopython:3.13python/cpython:3.13from
miss-islington:backport-0d8fb0b-3.13miss-islington/cpython:backport-0d8fb0b-3.13Copy head branch name to clipboard

Conversation

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 16, 2025

This splits the OS API specific functionality to get the number of threads out
from the fallback Python method and warning raising code itself. This way the
OS APIs can be queried before we've run
os.register_at_fork(after_in_parent=...) registered functions which
themselves may (re)start threads that would otherwise be detected.

This is best effort. If the OS APIs are either unavailable or fail, the
warning generating code still falls back to looking at the Python threading
state after the CPython interpreter world has been restarted and the
after_in_parent calls have been made. The common case for most Linux and macOS
environments should work today.

This also lines up with the existing TODO refactoring, we may choose to expose
this API to get the number of OS threads in the os module in the future.

Note: This is a simplified backport that maintains the void return type
for warn_about_fork_with_threads() and keeps PyErr_Clear() in the warning path,
as the error handling changes from fd8f42d are not needed in 3.14.
(cherry picked from commit 0d8fb0b)

Co-authored-by: Gregory P. Smith 68491+gpshead@users.noreply.github.com

…ythonGH-141438) (pythonGH-141614)

This splits the OS API specific functionality to get the number of threads out
from the fallback Python method and warning raising code itself.  This way the
OS APIs can be queried before we've run
`os.register_at_fork(after_in_parent=...)` registered functions which
themselves may (re)start threads that would otherwise be detected.

This is best effort.  If the OS APIs are either unavailable or fail, the
warning generating code still falls back to looking at the Python threading
state after the CPython interpreter world has been restarted and the
after_in_parent calls have been made.  The common case for most Linux and macOS
environments should work today.

This also lines up with the existing TODO refactoring, we may choose to expose
this API to get the number of OS threads in the `os` module in the future.

Note: This is a simplified backport that maintains the void return type
for warn_about_fork_with_threads() and keeps PyErr_Clear() in the warning path,
as the error handling changes from fd8f42d are not needed in 3.14.
(cherry picked from commit 0d8fb0b)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
@gpshead gpshead merged commit 61a24ea into python:3.13 Nov 17, 2025
45 checks passed
@miss-islington miss-islington deleted the backport-0d8fb0b-3.13 branch January 2, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

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