mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-46994: Accept explicit contextvars.Context in asyncio create_task() API (GH-31837)
This commit is contained in:
parent
2153daf0a0
commit
9523c0d84f
13 changed files with 209 additions and 65 deletions
|
@ -330,7 +330,7 @@ Creating Futures and Tasks
|
|||
|
||||
.. versionadded:: 3.5.2
|
||||
|
||||
.. method:: loop.create_task(coro, *, name=None)
|
||||
.. method:: loop.create_task(coro, *, name=None, context=None)
|
||||
|
||||
Schedule the execution of a :ref:`coroutine`.
|
||||
Return a :class:`Task` object.
|
||||
|
@ -342,9 +342,16 @@ Creating Futures and Tasks
|
|||
If the *name* argument is provided and not ``None``, it is set as
|
||||
the name of the task using :meth:`Task.set_name`.
|
||||
|
||||
An optional keyword-only *context* argument allows specifying a
|
||||
custom :class:`contextvars.Context` for the *coro* to run in.
|
||||
The current context copy is created when no *context* is provided.
|
||||
|
||||
.. versionchanged:: 3.8
|
||||
Added the *name* parameter.
|
||||
|
||||
.. versionchanged:: 3.11
|
||||
Added the *context* parameter.
|
||||
|
||||
.. method:: loop.set_task_factory(factory)
|
||||
|
||||
Set a task factory that will be used by
|
||||
|
@ -352,7 +359,7 @@ Creating Futures and Tasks
|
|||
|
||||
If *factory* is ``None`` the default task factory will be set.
|
||||
Otherwise, *factory* must be a *callable* with the signature matching
|
||||
``(loop, coro)``, where *loop* is a reference to the active
|
||||
``(loop, coro, context=None)``, where *loop* is a reference to the active
|
||||
event loop, and *coro* is a coroutine object. The callable
|
||||
must return a :class:`asyncio.Future`-compatible object.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue