mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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()`.)
This commit is contained in:
parent
42f54d1f92
commit
4ee2068c34
1 changed files with 8 additions and 4 deletions
|
@ -1014,7 +1014,7 @@ Introspection
|
||||||
Task Object
|
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
|
A :class:`Future-like <Future>` object that runs a Python
|
||||||
:ref:`coroutine <coroutine>`. Not thread-safe.
|
:ref:`coroutine <coroutine>`. Not thread-safe.
|
||||||
|
@ -1049,9 +1049,10 @@ Task Object
|
||||||
APIs except :meth:`Future.set_result` and
|
APIs except :meth:`Future.set_result` and
|
||||||
:meth:`Future.set_exception`.
|
:meth:`Future.set_exception`.
|
||||||
|
|
||||||
Tasks support the :mod:`contextvars` module. When a Task
|
An optional keyword-only *context* argument allows specifying a
|
||||||
is created it copies the current context and later runs its
|
custom :class:`contextvars.Context` for the *coro* to run in.
|
||||||
coroutine in the copied context.
|
If no *context* is provided, the Task copies the current context
|
||||||
|
and later runs its coroutine in the copied context.
|
||||||
|
|
||||||
.. versionchanged:: 3.7
|
.. versionchanged:: 3.7
|
||||||
Added support for the :mod:`contextvars` module.
|
Added support for the :mod:`contextvars` module.
|
||||||
|
@ -1063,6 +1064,9 @@ Task Object
|
||||||
Deprecation warning is emitted if *loop* is not specified
|
Deprecation warning is emitted if *loop* is not specified
|
||||||
and there is no running event loop.
|
and there is no running event loop.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.11
|
||||||
|
Added the *context* parameter.
|
||||||
|
|
||||||
.. method:: done()
|
.. method:: done()
|
||||||
|
|
||||||
Return ``True`` if the Task is *done*.
|
Return ``True`` if the Task is *done*.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue