]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-137109: refactor warning about threads when forking (#141438)
authorGregory P. Smith <68491+gpshead@users.noreply.github.com>
Thu, 13 Nov 2025 02:15:16 +0000 (18:15 -0800)
committerGitHub <noreply@github.com>
Thu, 13 Nov 2025 02:15:16 +0000 (18:15 -0800)
commit781cc68c3c814e46e6a74c3a6a32e0f9f8f7eb11
treef4639dd86ac9738a794c3c009de2009b0ac378a2
parent26b7df2430cd5a9ee772bfa6ee03a73bd0b11619
gh-137109: refactor warning about threads when forking (#141438)

* gh-137109: refactor warning about threads when forking

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.

* NEWS entry

* avoid "function-prototype" compiler warning?
Misc/NEWS.d/next/Library/2025-11-12-01-49-03.gh-issue-137109.D6sq2B.rst [new file with mode: 0644]
Modules/posixmodule.c