Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.11] gh-104254: Document the optional keyword-only "context" argument to Task constructor (GH-104251) #104258

Merged
merged 1 commit into from
May 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Doc/library/asyncio-task.rst
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,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.
Expand Down Expand Up @@ -1002,9 +1002,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.
Expand All @@ -1016,6 +1017,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*.
Expand Down