-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
[3.14] gh-137109: refactor warning about threads when forking (GH-141438) #141614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gpshead
merged 1 commit into
python:3.14
from
gpshead:claude/backport-781cc68-to-314-01HSABHvm74oTVhJNKK8BDHn
Nov 16, 2025
Merged
[3.14] gh-137109: refactor warning about threads when forking (GH-141438) #141614
gpshead
merged 1 commit into
python:3.14
from
gpshead:claude/backport-781cc68-to-314-01HSABHvm74oTVhJNKK8BDHn
Nov 16, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
Author
|
LOL having used "Claude Code for the web" to do the backport means the email address isn't going to work for CLA checks. I'll force push an amended commit using my identity. |
…ythonGH-141438) 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.
1ce093f to
95fb498
Compare
|
Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Nov 16, 2025
…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 <[email protected]>
|
GH-141639 is a backport of this pull request to the 3.13 branch. |
gpshead
added a commit
that referenced
this pull request
Nov 17, 2025
) (GH-141614) (GH-141639) [3.14] gh-137109: refactor warning about threads when forking (GH-141438) (GH-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 <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.
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 per discussion in #140191 on its own possible backport.