@@ -978,6 +978,23 @@ be specified by the build backend, as it will no longer be determined
978978automatically by the C compiler. For a running interpreter, the setting that
979979was 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
10321061Other language changes
10331062====================== 
0 commit comments