]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-137109: refactor warning about threads when forking (GH-141438) (GH-141614...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 17 Nov 2025 03:26:34 +0000 (04:26 +0100)
committerGitHub <noreply@github.com>
Mon, 17 Nov 2025 03:26:34 +0000 (19:26 -0800)
commit61a24ea572ef271736d0a1e1b0b7c188c8b9677a
treedaa8c531a25ee7d04b44d70060caf8d06fe66124
parent7beb7e8d35a58d52f8b91c095993b41eac17150a
[3.13] gh-137109: refactor warning about threads when forking (GH-141438) (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 fd8f42d3d1 are not needed in 3.14.
(cherry picked from commit 0d8fb0b8523769e24f249d19dab3781a10b50e8b)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
Misc/NEWS.d/next/Library/2025-11-12-01-49-03.gh-issue-137109.D6sq2B.rst [new file with mode: 0644]
Modules/posixmodule.c