summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItamar Ostricher <itamarost@gmail.com>2023-05-06 18:31:53 -0700
committerGitHub <noreply@github.com>2023-05-06 18:31:53 -0700
commit4ee2068c34bd45eddba7f6a8ee83f62d5b6932fc (patch)
tree5888646b4637a665f7981e4f50d478f641e5142d
parent42f54d1f9244784fec99e0610aa05a5051e594bb (diff)
downloadcpython-git-4ee2068c34bd45eddba7f6a8ee83f62d5b6932fc.tar.gz
gh-104254: Document the optional keyword-only "context" argument to Task constructor (#104251)
(This was added in 3.11. It was already documented for `create_task()`, but not for `Task()`.)
-rw-r--r--Doc/library/asyncio-task.rst12
1 files changed, 8 insertions, 4 deletions
diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst
index f8727b9806..a46ebc1c3d 100644
--- a/Doc/library/asyncio-task.rst
+++ b/Doc/library/asyncio-task.rst
@@ -1014,7 +1014,7 @@ Introspection
Task Object
===========
-.. class:: Task(coro, *, loop=None, name=None)
+.. class:: Task(coro, *, loop=None, name=None, context=None)
A :class:`Future-like <Future>` object that runs a Python
:ref:`coroutine <coroutine>`. Not thread-safe.
@@ -1049,9 +1049,10 @@ Task Object
APIs except :meth:`Future.set_result` and
:meth:`Future.set_exception`.
- Tasks support the :mod:`contextvars` module. When a Task
- is created it copies the current context and later runs its
- coroutine in the copied context.
+ An optional keyword-only *context* argument allows specifying a
+ custom :class:`contextvars.Context` for the *coro* to run in.
+ If no *context* is provided, the Task copies the current context
+ and later runs its coroutine in the copied context.
.. versionchanged:: 3.7
Added support for the :mod:`contextvars` module.
@@ -1063,6 +1064,9 @@ Task Object
Deprecation warning is emitted if *loop* is not specified
and there is no running event loop.
+ .. versionchanged:: 3.11
+ Added the *context* parameter.
+
.. method:: done()
Return ``True`` if the Task is *done*.