Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09e72b8

Browse files
committed
Rename flag to thread_inherit_context.
1 parent 16fa2c3 commit 09e72b8

12 files changed

Lines changed: 56 additions & 54 deletions

File tree

Doc/library/sys.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,9 @@ always available. Unless explicitly noted otherwise, all variables are read-only
598598
* - .. attribute:: flags.gil
599599
- :option:`-X gil <-X>` and :envvar:`PYTHON_GIL`
600600

601-
* - .. attribute:: flags.inherit_context
602-
- :option:`-X inherit_context <-X>` and :envvar:`PYTHON_INHERIT_CONTEXT`
601+
* - .. attribute:: flags.thread_inherit_context
602+
- :option:`-X thread_inherit_context <-X>` and
603+
:envvar:`PYTHON_THREAD_INHERIT_CONTEXT`
603604

604605
.. versionchanged:: 3.2
605606
Added ``quiet`` attribute for the new :option:`-q` flag.
@@ -631,7 +632,7 @@ always available. Unless explicitly noted otherwise, all variables are read-only
631632
Added the ``gil`` attribute.
632633

633634
.. versionchanged:: 3.14
634-
Added the ``inherit_context`` attribute.
635+
Added the ``thread_inherit_context`` attribute.
635636

636637

637638
.. data:: float_info

Doc/library/threading.rst

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,13 @@ since it is impossible to detect the termination of alien threads.
361361

362362
*context* is the :class:`~contextvars.Context` value to use when starting
363363
the thread. The default value is ``None`` which indicates that the
364-
:data:`sys.flags.inherit_context` flag controls the behaviour. If
364+
:data:`sys.flags.thread_inherit_context` flag controls the behaviour. If
365365
the flag is true, threads will start with a copy of the context of the
366-
caller of :meth:`~Thread.start`. If false, they will start with
367-
an empty context. To explicitly start with an empty context,
368-
pass a new instance of :class:`~contextvars.Context()`. To explicitly
369-
start with a copy of the current context, pass the value from
370-
:func:`~contextvars.copy_context`. The flag defaults true on
371-
free-threaded builds and false otherwise.
366+
caller of :meth:`~Thread.start`. If false, they will start with an empty
367+
context. To explicitly start with an empty context, pass a new instance of
368+
:class:`~contextvars.Context()`. To explicitly start with a copy of the
369+
current context, pass the value from :func:`~contextvars.copy_context`. The
370+
flag defaults true on free-threaded builds and false otherwise.
372371

373372
If the subclass overrides the constructor, it must make sure to invoke the
374373
base class constructor (``Thread.__init__()``) before doing anything else to

Doc/using/cmdline.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,12 @@ Miscellaneous options
628628

629629
.. versionadded:: 3.13
630630

631-
* :samp:`-X inherit_context={0,1}` causes :class:`~threading.Thread`
631+
* :samp:`-X thread_inherit_context={0,1}` causes :class:`~threading.Thread`
632632
to, by default, use a copy of context of of the caller of
633633
``Thread.start()`` when starting. Otherwise, threads will start
634634
with an empty context. If unset, the value of this option defaults
635635
to ``1`` on free-threaded builds and to ``0`` otherwise. See also
636-
:envvar:`PYTHON_INHERIT_CONTEXT`.
636+
:envvar:`PYTHON_THREAD_INHERIT_CONTEXT`.
637637

638638
.. versionadded:: 3.14
639639

@@ -1230,13 +1230,13 @@ conflict.
12301230

12311231
.. versionadded:: 3.13
12321232

1233-
.. envvar:: PYTHON_INHERIT_CONTEXT
1233+
.. envvar:: PYTHON_THREAD_INHERIT_CONTEXT
12341234

12351235
If this variable is set to ``1`` then :class:`~threading.Thread` will,
12361236
by default, use a copy of context of of the caller of ``Thread.start()``
12371237
when starting. Otherwise, new threads will start with an empty context.
12381238
If unset, this variable defaults to ``1`` on free-threaded builds and to
1239-
``0`` otherwise. See also :option:`-X inherit_context<-X>`.
1239+
``0`` otherwise. See also :option:`-X thread_inherit_context<-X>`.
12401240

12411241
.. versionadded:: 3.14
12421242

Include/cpython/initconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ typedef struct PyConfig {
179179
int use_frozen_modules;
180180
int safe_path;
181181
int int_max_str_digits;
182-
int inherit_context;
182+
int thread_inherit_context;
183183
#ifdef __APPLE__
184184
int use_system_logger;
185185
#endif

Lib/test/test_capi/test_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_config_get(self):
5555
("filesystem_errors", str, None),
5656
("hash_seed", int, None),
5757
("home", str | None, None),
58-
("inherit_context", int, None),
58+
("thread_inherit_context", int, None),
5959
("import_time", bool, None),
6060
("inspect", bool, None),
6161
("install_signal_handlers", bool, None),
@@ -171,7 +171,7 @@ def test_config_get_sys_flags(self):
171171
("warn_default_encoding", "warn_default_encoding", False),
172172
("safe_path", "safe_path", False),
173173
("int_max_str_digits", "int_max_str_digits", False),
174-
# "gil" and "inherit_context" are tested below
174+
# "gil" and "thread_inherit_context" are tested below
175175
):
176176
with self.subTest(flag=flag, name=name, negate=negate):
177177
value = config_get(name)
@@ -189,7 +189,7 @@ def test_config_get_sys_flags(self):
189189
self.assertEqual(sys.flags.gil, expected)
190190

191191
expected_inherit_context = 1 if support.Py_GIL_DISABLED else 0
192-
self.assertEqual(sys.flags.inherit_context, expected_inherit_context)
192+
self.assertEqual(sys.flags.thread_inherit_context, expected_inherit_context)
193193

194194
def test_config_get_non_existent(self):
195195
# Test PyConfig_Get() on non-existent option name

Lib/test/test_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,14 @@ def test_context_thread_inherit(self):
392392
cvar = contextvars.ContextVar('cvar')
393393

394394
def run_context_none():
395-
if sys.flags.inherit_context:
395+
if sys.flags.thread_inherit_context:
396396
expected = 1
397397
else:
398398
expected = None
399399
self.assertEqual(cvar.get(None), expected)
400400

401401
# By default, context is inherited based on the
402-
# sys.flags.inherit_context option.
402+
# sys.flags.thread_inherit_context option.
403403
cvar.set(1)
404404
thread = threading.Thread(target=run_context_none)
405405
thread.start()

Lib/test/test_embed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
f'{VERSION_MINOR}{ABI_THREAD}/lib-dynload')
6262

6363
if support.Py_GIL_DISABLED:
64-
DEFAULT_INHERIT_CONTEXT = 1
64+
DEFAULT_THREAD_INHERIT_CONTEXT = 1
6565
else:
66-
DEFAULT_INHERIT_CONTEXT = 0
66+
DEFAULT_THREAD_INHERIT_CONTEXT = 0
6767

6868
# If we are running from a build dir, but the stdlib has been installed,
6969
# some tests need to expect different results.
@@ -590,7 +590,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
590590
'tracemalloc': 0,
591591
'perf_profiling': 0,
592592
'import_time': False,
593-
'inherit_context': DEFAULT_INHERIT_CONTEXT,
593+
'thread_inherit_context': DEFAULT_THREAD_INHERIT_CONTEXT,
594594
'code_debug_ranges': True,
595595
'show_ref_count': False,
596596
'dump_refs': False,

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ def test_pythontypes(self):
18451845
# symtable entry
18461846
# XXX
18471847
# sys.flags
1848-
# FIXME: The +2 is for the 'gil' and 'inherit_context' flags and
1848+
# FIXME: The +2 is for the 'gil' and 'thread_inherit_context' flags and
18491849
# will not be necessary once gh-122575 is fixed
18501850
check(sys.flags, vsize('') + self.P * (2 + len(sys.flags)))
18511851

Lib/threading.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -891,11 +891,11 @@ class is implemented.
891891
892892
*context* is the contextvars.Context value to use for the thread.
893893
The default value is None, which means to check
894-
sys.flags.inherit_context. If that flag is true, use a copy of
895-
the context of the caller. If false, use an empty context. To
894+
sys.flags.thread_inherit_context. If that flag is true, use a copy
895+
of the context of the caller. If false, use an empty context. To
896896
explicitly start with an empty context, pass a new instance of
897-
contextvars.Context(). To explicitly start with a copy of the
898-
current context, pass the value from contextvars.copy_context().
897+
contextvars.Context(). To explicitly start with a copy of the current
898+
context, pass the value from contextvars.copy_context().
899899
900900
If a subclass overrides the constructor, it must make sure to invoke
901901
the base class constructor (Thread.__init__()) before doing anything
@@ -985,7 +985,7 @@ def start(self):
985985

986986
if self._context is None:
987987
# No context provided
988-
if _sys.flags.inherit_context:
988+
if _sys.flags.thread_inherit_context:
989989
# start with a copy of the context of the caller
990990
self._context = _contextvars.copy_context()
991991
else:

Misc/NEWS.d/next/Core_and_Builtins/2025-01-06-10-55-41.gh-issue-128555.tAK_AY.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
Add the :data:`sys.flags.inherit_context` flag.
1+
Add the :data:`sys.flags.thread_inherit_context` flag.
22

33
* This flag is set to true by default on the free-threaded build
44
and false otherwise. If the flag is true, starting a new thread using
55
:class:`threading.Thread` will, by default, use a copy of the
66
:class:`contextvars.Context` from the caller of
77
:meth:`threading.Thread.start` rather than using an empty context.
88

9-
* Add the :option:`-X inherit_context <-X>` command-line option and
10-
:envvar:`PYTHON_INHERIT_CONTEXT` environment variable, which set the
11-
:data:`~sys.flags.inherit_context` flag.
9+
* Add the :option:`-X thread_inherit_context <-X>` command-line option and
10+
:envvar:`PYTHON_THREAD_INHERIT_CONTEXT` environment variable, which set the
11+
:data:`~sys.flags.thread_inherit_context` flag.
1212

1313
* Add the ``context`` keyword parameter to :class:`~threading.Thread`. It can
1414
be used to explicitly pass a context value to be used by a new thread.

0 commit comments

Comments
 (0)