Skip to content

Commit f51bb0e

Browse files
committed
Add blurb, update docs/comments.
1 parent cef04e2 commit f51bb0e

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Doc/library/threading.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,10 @@ since it is impossible to detect the termination of alien threads.
359359
If ``None`` (the default), the daemonic property is inherited from the
360360
current thread.
361361

362-
*context* is the `contextvars.Context` value to use while running the thread.
363-
The default is to inherit the context of the caller of :meth:`~Thread.start`.
364-
To start with an empty context, pass a new instance of
365-
:class:`contextvars.Context()`
362+
*context* is the ``contextvars.Context`` value to use while running
363+
the thread. The default value is ``None`` which means to use a copy
364+
of the context of the caller of :meth:`~Thread.start`. To start with
365+
an empty context, pass a new instance of :class:`contextvars.Context()`
366366

367367
If the subclass overrides the constructor, it must make sure to invoke the
368368
base class constructor (``Thread.__init__()``) before doing anything else to
@@ -375,8 +375,10 @@ since it is impossible to detect the termination of alien threads.
375375
Use the *target* name if *name* argument is omitted.
376376

377377
.. versionchanged:: 3.14
378-
Added the *context* parameter. Previously threads always ran with an empty
379-
context.
378+
Threads now inherit the context of the caller of :meth:`Thread.start`
379+
instead of starting with an empty context. The ``context`` parameter
380+
was added. Pass a new ``contextvars.Context()`` if your thread
381+
requires an empty context.
380382

381383
.. method:: start()
382384

Lib/threading.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,9 +890,10 @@ class is implemented.
890890
*kwargs* is a dictionary of keyword arguments for the target
891891
invocation. Defaults to {}.
892892
893-
*context* is the contextvars.Context value to use for the thread. The default
894-
is to inherit the context of the caller. To start with an empty context,
895-
pass a new instance of contextvars.Context().
893+
*context* is the contextvars.Context value to use for the thread.
894+
The default value is None, which means to use a copy of the context
895+
of the caller. To start with an empty context, pass a new instance
896+
of contextvars.Context().
896897
897898
If a subclass overrides the constructor, it must make sure to invoke
898899
the base class constructor (Thread.__init__()) before doing anything
@@ -981,7 +982,7 @@ def start(self):
981982
_limbo[self] = self
982983

983984
if self._context is None:
984-
# No context provided, inherit the context of the caller.
985+
# No context provided, inherit a copy of the context of the caller.
985986
self._context = _contextvars.copy_context()
986987

987988
try:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Starting a new thread using :class:`threading.Thread` will now, by default,
2+
use a copy of the :class:`contextvars.Context` from the caller of
3+
:meth:`Thread.start` rather than using an empty context. The `_contextvars`
4+
module is now built-in.

0 commit comments

Comments
 (0)