]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)
authorNeil Schemenauer <nas-github@arctrix.com>
Wed, 9 Apr 2025 23:18:54 +0000 (16:18 -0700)
committerGitHub <noreply@github.com>
Wed, 9 Apr 2025 23:18:54 +0000 (16:18 -0700)
commitd687900f98114bb5910daad9553ae381d7daf94b
tree6f7c31164aa867d1bbf8c82f5eeb4cb9129dd3b0
parente5237541a098e32a70fc621dee08721a72be7eb8
gh-128384: Use a context variable for warnings.catch_warnings (gh-130010)

Make `warnings.catch_warnings()` use a context variable for holding
the warning filtering state if the `sys.flags.context_aware_warnings`
flag is set to true.  This makes using the context manager thread-safe in
multi-threaded programs.

Add the `sys.flags.thread_inherit_context` flag.  If true, starting a new
thread with `threading.Thread` will use a copy of the context
from the caller of `Thread.start()`.

Both these flags are set to true by default for the free-threaded build
and false for the default build.

Move the Python implementation of warnings.py into _py_warnings.py.

Make _contextvars a builtin module.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
41 files changed:
Doc/howto/free-threading-python.rst
Doc/library/decimal.rst
Doc/library/sys.rst
Doc/library/threading.rst
Doc/library/warnings.rst
Doc/using/cmdline.rst
Include/cpython/initconfig.h
Include/internal/pycore_global_objects_fini_generated.h
Include/internal/pycore_global_strings.h
Include/internal/pycore_interp_structs.h
Include/internal/pycore_runtime_init_generated.h
Include/internal/pycore_unicodeobject_generated.h
Lib/_py_warnings.py [new file with mode: 0644]
Lib/test/support/__init__.py
Lib/test/support/warnings_helper.py
Lib/test/test_capi/test_config.py
Lib/test/test_context.py
Lib/test/test_decimal.py
Lib/test/test_embed.py
Lib/test/test_free_threading/test_races.py
Lib/test/test_support.py
Lib/test/test_sys.py
Lib/test/test_warnings/__init__.py
Lib/threading.py
Lib/warnings.py
Makefile.pre.in
Misc/NEWS.d/next/Core_and_Builtins/2025-01-06-10-55-41.gh-issue-128555.tAK_AY.rst [new file with mode: 0644]
Misc/NEWS.d/next/Library/2025-02-11-10-22-11.gh-issue-128384.jyWEkA.rst [new file with mode: 0644]
Modules/Setup
Modules/Setup.stdlib.in
Modules/config.c.in
PCbuild/pythoncore.vcxproj
PCbuild/pythoncore.vcxproj.filters
Python/_contextvars.c [moved from Modules/_contextvarsmodule.c with 97% similarity]
Python/_warnings.c
Python/clinic/_contextvars.c.h [moved from Modules/clinic/_contextvarsmodule.c.h with 100% similarity]
Python/initconfig.c
Python/stdlib_module_names.h
Python/sysmodule.c
configure
configure.ac