8000 Add whatsnew text for warnings module changes. (gh-135869) · python/cpython@1f5e23f · GitHub
[go: up one dir, main page]

Skip to content

Commit 1f5e23f

Browse files
authored
Add whatsnew text for warnings module changes. (gh-135869)
1 parent 0fadd9f commit 1f5e23f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,23 @@ be specified by the build backend, as it will no longer be determined
978978
automatically by the C compiler. For a running interpreter, the setting that
979979
was used at compile time can be found using :func:`sysconfig.get_config_var`.
980980

981+
A new flag has been added, :data:`~sys.flags.context_aware_warnings`. This
982+
flag defaults to true for the free-threaded build and false for the GIL-enabled
983+
build. If the flag is true then the :class:`warnings.catch_warnings` context
984+
manager uses a context variable for warning filters. This makes the context
985+
manager behave predicably when used with multiple threads or asynchronous
986+
tasks.
987+
988+
A new flag has been added, :data:`~sys.flags.thread_inherit_context`. This flag
989+
defaults to true for the free-threaded build and false for the GIL-enabled
990+
build. If the flag is true then threads created with :class:`threading.Thread`
991+
start with a copy of the :class:`~contextvars.Context()` of the caller of
992+
:meth:`~threading.Thread.start`. Most significantly, this makes the warning
993+
filtering context established by :class:`~warnings.catch_warnings` be
994+
"inherited" by threads (or asyncio tasks) started within that context. It also
995+
affects other modules that use context variables, such as the :mod:`decimal`
996+
context manager.
997+
981998

982999
.. _whatsnew314-pyrepl-highlighting:
9831000

@@ -1028,6 +1045,18 @@ Please report any bugs or major performance regressions that you encounter!
10281045

10291046
.. seealso:: :pep:`744`
10301047

1048+
Concurrent safe warnings control
1049+
--------------------------------
1050+
1051+
The :class:`warnings.catch_warnings` context manager will now optionally
1052+
use a context variable for warning filters. This is enabled by setting
1053+
the :data:`~sys.flags.context_aware_warnings` flag, either with the ``-X``
1054+
command-line option or an environment variable. This gives predicable
1055+
warnings control when using :class:`~warnings.catch_warnings` combined with
1056+
multiple threads or asynchronous tasks. The flag defaults to true for the
1057+
free-threaded build and false for the GIL-enabled build.
1058+
1059+
(Contributed by Neil Schemenauer and Kumar Aditya in :gh:`130010`.)
10311060

10321061
Other language changes
10331062
======================

0 commit comments

Comments
 (0)
0