cpython/Modules
Miss Islington (bot) 61a24ea572
[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 0d8fb0b852)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
2025-11-16 19:26:34 -08:00
..
_blake2 [3.13] gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (GH-134713) (#134962) 2025-06-01 10:27:02 +02:00
_ctypes [3.13] Remove unreachable break statements in _ctypes_test.c (GH-140585) (#140588) 2025-10-25 18:39:54 +03:00
_decimal [3.13] gh-102431: Clarify constraints on operands of Decimal logical operations (GH-102836) (#140106) 2025-10-14 15:45:02 +02:00
_hacl gh-99108: Refresh HACL*; update modules accordingly; fix namespacing (GH-117237) 2024-03-26 00:35:26 +00:00
_io [3.13] gh-141311: Avoid assertion in BytesIO.readinto() (GH-141333) (GH-141478) 2025-11-12 23:37:06 +02:00
_multiprocessing [3.13] gh-111178: fix UBSan failures in Modules/_multiprocessing/semaphore.c (GH-129084) (#129100) 2025-01-20 21:05:52 +00:00
_sqlite [3.13] gh-139283: correctly handle size limit in cursor.fetchmany() (GH-139296) (#139444) 2025-10-07 13:33:40 +02:00
_sre [3.13] gh-140979: Fix off-by-one error in the RE code validator (GH-140984) (GH-141000) 2025-11-04 18:16:40 +02:00
_ssl [3.13] gh-137583: Only lock the SSL context, not the SSL socket (GH-137588) (GH-137613) 2025-08-11 22:05:13 -04:00
_testcapi [3.13] gh-136288: Fix error message in _testcapi/vectorcall.c (GH-136258) (GH-136295) 2025-07-04 16:17:10 +00:00
_testinternalcapi [3.13] gh-135641: Fix flaky test_capi.test_lock_two_threads test case (gh-135642) (gh-135688) 2025-06-18 18:47:59 +00:00
_testlimitedcapi [3.13] gh-132657: add regression test for PySet_Contains with unhashable type (GH-141411) (#141467) 2025-11-12 21:12:18 +05:30
_xxtestfuzz [3.13] gh-121023: Improve _xxtestfuzz/README.rst (GH-121024) (#124140) 2024-09-23 17:23:54 -07:00
cjkcodecs [3.13] gh-101828: Fix jisx0213 codecs removing null characters (gh-139340) (gh-140112) 2025-10-14 14:48:29 +00:00
clinic [3.13] gh-140615: Update docstrings in the fcntl module (GH-140619) (GH-141231) (GH-141232) 2025-11-08 11:50:17 +00:00
expat [3.13] gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (GH-139234) (#139367) 2025-11-02 12:39:11 +00:00
_abc.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
_asynciomodule.c [3.13] gh-126405: fix use-after-free in _asyncio.Future.remove_done_callback (GH-126733) (#126736) 2024-11-12 13:04:27 +00:00
_bisectmodule.c [3.13] gh-126035: add missing whitespace to *Py_EnterRecursiveCall() messages (GH-126036) (#126058) 2024-10-27 22:19:37 +00:00
_bz2module.c [3.13] gh-116946: Revert GC protocol for immutable empty heap types (GH-138322, GH-138323, GH-138326) (#138337) 2025-09-01 21:14:47 +05:30
_codecsmodule.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
_collectionsmodule.c [3.13] gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614) (#136126) 2025-07-01 11:26:52 +02:00
_contextvarsmodule.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
_csv.c [3.13] gh-137986: Fix and improve the csv functions docstrings (GH-137987) (GH-138108) 2025-08-24 08:37:41 +00:00
_curses_panel.c [3.13] gh-116946: fully implement GC protocol for _curses_panel.panel (GH-138333) (#138428) 2025-09-06 12:17:57 +02:00
_cursesmodule.c [3.13] gh-137920: Fix semantically relevant typo in curses.window.attron (GH-137940) (GH-138507) 2025-10-07 22:22:18 +02:00
_datetimemodule.c [3.13] gh-52551: Fix encoding issues in strftime() (GH-125193) (GH-125657) 2024-10-17 22:48:34 +03:00
_dbmmodule.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
_elementtree.c [3.13] gh-139210: Fix use-after-free in xml.etree.ElementTree.iterparse() (GH-139211) (GH-139456) 2025-09-30 18:14:44 +00:00
_functoolsmodule.c [3.13] GH-140590: Fix setstate for functools.partial C-module (GH-140671) (#140699) 2025-10-28 18:14:14 +05:30
_gdbmmodule.c [3.13] gh-140272: Fix memory leak in _gdbm.gdbm.clear() (GH-140274) (GH-140289) 2025-10-18 11:00:10 +00:00
_hashopenssl.c [3.13] gh-116946: Revert GC protocol for immutable empty heap types (GH-138322, GH-138323, GH-138326) (#138337) 2025-09-01 21:14:47 +05:30
_heapqmodule.c [3.13] Fix comments for heapq.siftup_max (GH-135359) (#136233) 2025-07-03 10:15:01 +00:00
_interpchannelsmodule.c [3.13] gh-140306: Fix memory leaks in cross-interpreter data handling (GH-140307) (GH-140357) 2025-10-20 10:13:15 +00:00
_interpqueuesmodule.c [3.13] gh-140306: Fix memory leaks in cross-interpreter data handling (GH-140307) (GH-140357) 2025-10-20 10:13:15 +00:00
_interpreters_common.h [3.13] gh-76785: Expand How Interpreter Channels Handle Interpreter Finalization (gh-121811) 2024-07-15 20:15:47 +00:00
_interpretersmodule.c [3.13] gh-135839: Fix module_traverse and module_clear in subinterp modules (GH-135937) (GH-135943) 2025-08-04 14:34:47 +02:00
_json.c [3.13] gh-131884: Fix incorrect formatting in json.dumps() when using indent and skipkeys=True (GH-132200) (GH-135061) 2025-06-05 14:38:11 +00:00
_localemodule.c [3.13] gh-130567: Fix possible crash in locale.strxfrm() (GH-138940) (GH-139266) 2025-09-24 13:48:08 +02:00
_lsprof.c [3.13] gh-132250: Clear error in lsprof callback when method descriptor raises an excep… (GH-132251) (#132281) 2025-04-08 17:19:40 -04:00
_lzmamodule.c [3.13] gh-116946: Revert GC protocol for immutable empty heap types (GH-138322, GH-138323, GH-138326) (#138337) 2025-09-01 21:14:47 +05:30
_math.h gh-101678: refactor the math module to use special functions from c11 (GH-101679) 2023-02-09 00:40:52 -08:00
_opcode.c [3.13] gh-120642: Move private PyCode APIs to the internal C API (#120643) (#121043) 2024-06-26 15:35:19 +02:00
_operator.c [3.13] gh-127065: Make methodcaller thread-safe in free threading build (GH-127109) (GH-127150) 2024-11-22 14:51:40 +00:00
_pickle.c [3.13] gh-135321: Always raise a correct exception for BINSTRING argument > 0x7fffffff in pickle (GH-135322) (GH-135383) 2025-06-11 14:00:59 +03:00
_posixsubprocess.c [3.13] fix comment reference from man 7 signal to man 7 signal-safety (GH-138554) (#138595) 2025-09-06 19:02:33 +00:00
_queuemodule.c [3.13] gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614) (#136126) 2025-07-01 11:26:52 +02:00
_randommodule.c [3.13] Fix a compiler warning in _randommodule.c (GH-141058) (#141064) 2025-11-05 19:08:41 +00:00
_scproxy.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
_ssl.c [3.13] gh-139748: fix leaks in AC error paths when using unicode FS-b… (#139792) 2025-10-08 22:21:49 +05:30
_ssl.h GH-103092: isolate _ssl (#104725) 2023-05-22 06:14:48 +05:30
_ssl_data_31.h gh-103142: Upgrade binary builds and CI to OpenSSL 1.1.1u (#105174) 2023-06-01 09:42:18 -07:00
_ssl_data_111.h gh-103142: Upgrade binary builds and CI to OpenSSL 1.1.1u (#105174) 2023-06-01 09:42:18 -07:00
_ssl_data_300.h gh-103142: Upgrade binary builds and CI to OpenSSL 1.1.1u (#105174) 2023-06-01 09:42:18 -07:00
_stat.c [3.13] gh-108765: fix comment about macro definitions in _stat.c post GH-108854 (GH-136027) (#136044) 2025-06-27 15:39:18 +00:00
_statisticsmodule.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
_struct.c [3.13] gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614) (#136126) 2025-07-01 11:26:52 +02:00
_suggestions.c [3.13] gh-131936: Strengthen check in _suggestions._generate_suggestions (GH-131945) (#131949) 2025-03-31 17:54:20 +00:00
_sysconfig.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
_testbuffer.c gh-116322: Rename PyModule_ExperimentalSetGIL to PyUnstable_Module_SetGIL (GH-118645) 2024-05-06 18:59:36 +02:00
_testcapi_feature_macros.inc gh-91325: Skip Stable ABI checks with Py_TRACE_REFS special build (GH-92046) 2024-01-29 16:45:31 +01:00
_testcapimodule.c [3.13] gh-87135: Hang non-main threads that attempt to acquire the GIL during finalization (GH-105805) (GH-137827) 2025-08-17 09:08:14 -07:00
_testclinic.c [3.13] gh-132753: Argument Clinic: Fix support of c_default for the bool converter (GH-132754) (GH-132766) 2025-04-21 07:10:31 +00:00
_testclinic_limited.c gh-116322: Rename PyModule_ExperimentalSetGIL to PyUnstable_Module_SetGIL (GH-118645) 2024-05-06 18:59:36 +02:00
_testexternalinspection.c [3.13] gh-130052: Fix search_map_for_section() error handling (GH-132594) (#132598) 2025-04-16 14:21:58 +00:00
_testimportmultiple.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
_testinternalcapi.c [3.13] gh-127791: Fix, document, and test PyUnstable_AtExit (GH-127793) (#127819) 2024-12-11 13:40:45 +00:00
_testlimitedcapi.c [3.13] gh-111495: Add PyFile tests (#129449) (#129477) 2025-01-30 20:29:27 +01:00
_testmultiphase.c [3.13] gh-129405: Fix doc for Py_mod_multiple_interpreters default, and add test (GH-129406) (GH-130507) 2025-02-24 16:49:35 +01:00
_testsinglephase.c [3.13] gh-123880: Allow recursive import of single-phase-init modules (GH-123950) (#124273) 2024-09-23 12:56:00 -07:00
_threadmodule.c [3.13] gh-137017: Ensure Thread.is_alive() only returns False after the underlying OS thread exits (gh-137315) (gh-138917) 2025-09-15 14:28:05 +01:00
_tkinter.c [3.13] gh-124111: Fix TCL 9 thread detection (GH-141483) 2025-11-12 22:44:01 +00:00
_tracemalloc.c [3.13] gh-128679: Fix tracemalloc.stop() race conditions (#128897) 2025-01-18 23:39:07 +00:00
_typingmodule.c [3.13] gh-123448: Move _PyNoDefault_Type to the static types array (GH-123449) (#123450) 2024-08-28 18:57:28 -07:00
_uuidmodule.c [3.13] gh-132710: only use stable _uuid.generate_time_safe() to deduce MAC address (GH-132901) (#134704) 2025-08-05 07:56:03 +00:00
_weakref.c [3.13] gh-120974: Make _asyncio._leave_task atomic in the free-threaded build (GH-122139) (#122186) 2024-07-23 17:30:58 +00:00
_winapi.c gh-128217: Validate the normalized_environment variable instead of the similarly named function (GH-128220) 2024-12-24 13:29:56 +00:00
_zoneinfo.c [3.13] gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614) (#136126) 2025-07-01 11:26:52 +02:00
addrinfo.h gh-95174: WASI: skip missing sockets functions (GH-95179) 2022-07-27 08:19:23 +02:00
arraymodule.c [3.13] gh-140474: Fix memory leak in array.array (GH-140478) (GH-140499) 2025-10-23 12:18:01 +00:00
atexitmodule.c [3.13] gh-127791: Fix, document, and test PyUnstable_AtExit (GH-127793) (#127819) 2024-12-11 13:40:45 +00:00
binascii.c gh-118314: Fix padding edge case in binascii.a2b_base64 strict mode (GH-118320) 2024-05-07 11:18:45 +02:00
cmathmodule.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
config.c.in gh-104169: Fix test_peg_generator after tokenizer refactoring (#110727) 2023-10-12 09:34:35 +02:00
errnomodule.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
faulthandler.c [3.13] gh-130163: Fix crashes related to PySys_GetObject() (GH-130503) (GH-130556) 2025-02-25 22:50:26 +00:00
fcntlmodule.c [3.13] gh-140615: Update docstrings in the fcntl module (GH-140619) (GH-141231) (GH-141232) 2025-11-08 11:50:17 +00:00
gc_weakref.txt Fix links to old SF bugs (#95648) 2022-08-04 18:12:35 +02:00
gcmodule.c [3.13] gh-138659: Typo in the gc module docstring (GH-138660) (#138663) 2025-09-08 14:39:43 +00:00
getaddrinfo.c gh-108767: Replace ctype.h functions with pyctype.h functions (#108772) 2023-09-01 18:36:53 +02:00
getbuildinfo.c gh-106320: Remove private pylifecycle.h functions (#106400) 2023-07-04 09:41:43 +00:00
getnameinfo.c gh-95174: WASI: skip missing sockets functions (GH-95179) 2022-07-27 08:19:23 +02:00
getpath.c [3.13] gh-121103: Put free-threaded libraries in lib/python3.14t (GH-121293) (#121631) 2024-07-11 21:00:28 +00:00
getpath.py [3.13] gh-121103: Put free-threaded libraries in lib/python3.14t (GH-121293) (#121631) 2024-07-11 21:00:28 +00:00
getpath_noop.c
grpmodule.c [3.13] gh-126316: Make grp.getgrall() thread-safe: add a mutex (#127055) (#127104) 2024-11-26 12:01:50 +01:00
hashlib.h [3.13] gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (GH-134713) (#134962) 2025-06-01 10:27:02 +02:00
itertoolsmodule.c [3.13] gh-126618: fix repr(itertools.count(sys.maxsize)) (GH-127048) (#127508) 2024-12-02 13:38:13 +00:00
ld_so_aix.in
main.c [3.13] gh-129900: Fix SystemExit return codes when the REPL is started from the command line (GH-129901) (#131734) 2025-03-25 20:15:00 +00:00
makesetup [3.13] gh-116622: Rename build variable MODULE_LDFLAGS back to LIBPYTHON (GH-122764) (GH-122842) 2024-08-09 14:45:04 -07:00
makexp_aix
mathmodule.c [3.13] gh-132876: workaround broken ldexp() on Windows 10 (GH-133135) (#134685) 2025-05-25 22:39:34 -05:00
md5module.c [3.13] gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (GH-134713) (#134962) 2025-06-01 10:27:02 +02:00
mmapmodule.c [3.13] gh-138204: Forbid expansion of a shared anonymous mmap on Linux (GH-138220) (GH-138387) 2025-09-03 11:33:08 +03:00
overlapped.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
posixmodule.c [3.13] gh-137109: refactor warning about threads when forking (GH-141438) (GH-141614) (GH-141639) 2025-11-16 19:26:34 -08:00
posixmodule.h gh-85283: Convert grp extension to the limited C API (#116611) 2024-03-12 00:46:53 +00:00
pwdmodule.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
pyexpat.c [3.13] gh-90949: add Expat API to prevent XML deadly allocations (CVE-2025-59375) (GH-139234) (#139367) 2025-11-02 12:39:11 +00:00
readline.c [3.13] gh-122431: Disallow negative values in readline.append_history_file (GH-122469) (#127641) 2024-12-05 18:15:44 +01:00
README
resource.c [3.13] gh-137044: Support large limit values in getrlimit() and setrlimit() (GH-137338) (GH-137507) 2025-08-07 09:37:02 +00:00
rotatingtree.c [3.13] gh-116181: Remove Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE in rotatingtree.c (GH-121260) (#121307) 2024-07-03 07:59:26 +00:00
rotatingtree.h
selectmodule.c [3.13] gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) (GH-122012) 2024-07-19 09:13:08 +00:00
Setup gh-76785: Rename _xxsubinterpreters to _interpreters (gh-117791) 2024-04-24 16:18:24 +00:00
Setup.bootstrap.in gh-110721: Remove unused code from suggestions.c after moving PyErr_Display to use the traceback module (#113712) 2024-01-08 15:10:45 +00:00
Setup.stdlib.in [3.13] gh-111495: Add PyFile tests (#129449) (#129477) 2025-01-30 20:29:27 +01:00
sha1module.c [3.13] gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (GH-134713) (#134962) 2025-06-01 10:27:02 +02:00
sha2module.c [3.13] gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (GH-134713) (#134962) 2025-06-01 10:27:02 +02:00
sha3module.c [3.13] gh-134696: align OpenSSL and HACL*-based hash functions constructors AC signatures (GH-134713) (#134962) 2025-06-01 10:27:02 +02:00
signalmodule.c [3.13] gh-137490: Fix signal.sigwaitinfo() on NetBSD (GH-137523) (GH-138936) 2025-09-15 16:43:32 +00:00
socketmodule.c [3.13] gh-100218: correctly set errno when socket.if_{nametoindex,indextoname} raise OSError (GH-140905) (#141285) 2025-11-09 13:31:49 +00:00
socketmodule.h [3.13] gh-132429: Fix support of Bluetooth sockets on NetBSD and DragonFly BSD (GH-132431) (GH-132458) 2025-04-13 01:22:41 +03:00
symtablemodule.c [3.13] gh-139748: fix leaks in AC error paths when using unicode FS-b… (#139792) 2025-10-08 22:21:49 +05:30
syslogmodule.c [3.13] gh-130163: Fix crashes related to PySys_GetObject() (GH-130503) (GH-130556) 2025-02-25 22:50:26 +00:00
termios.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
timemodule.c [3.13] gh-130617 : fix time_clockid_converter on DragonFlyBSD (GH-130634) (#130666) 2025-02-28 08:19:45 +00:00
tkappinit.c gh-103538: Remove unused TK_AQUA code (GH-103539) 2023-05-10 18:53:13 +00:00
tkinter.h gh-103532: Remove TKINTER_PROTECT_LOADTK code (GH-103535) 2023-04-14 09:04:16 -05:00
unicodedata.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
unicodedata_db.h gh-96954: Fix make regen-unicodedata in out-of-tree builds (#112118) 2023-11-15 16:42:17 +00:00
unicodename_db.h gh-96954: Fix make regen-unicodedata in out-of-tree builds (#112118) 2023-11-15 16:42:17 +00:00
winreparse.h
xxlimited.c [3.13] gh-134160: Use PyModuleDef.m_free in the example module xxlimited (GH-135174) (GH-135214) 2025-06-07 11:03:32 +02:00
xxlimited_35.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
xxmodule.c [3.13] gh-122040: reword Modules/xxmodule.c module-level comment (GH-132201) (#132207) 2025-04-07 08:27:34 +00:00
xxsubtype.c gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
zlibmodule.c [3.13] gh-116946: fully implement GC protocol for zlib objects (GH-138290) (#138328) 2025-09-01 12:25:11 +02:00

Source files for standard library extension modules,
and former extension modules that are now builtin modules.