@@ -1014,7 +1014,7 @@ Introspection
1014
1014
Task Object
1015
1015
===========
1016
1016
1017
- .. class :: Task(coro, *, loop=None, name=None)
1017
+ .. class :: Task(coro, *, loop=None, name=None, context=None )
1018
1018
1019
1019
A :class: `Future-like <Future> ` object that runs a Python
1020
1020
:ref: `coroutine <coroutine >`. Not thread-safe.
@@ -1049,9 +1049,10 @@ Task Object
1049
1049
APIs except :meth: `Future.set_result ` and
1050
1050
:meth: `Future.set_exception `.
1051
1051
1052
- Tasks support the :mod: `contextvars ` module. When a Task
1053
- is created it copies the current context and later runs its
1054
- coroutine in the copied context.
1052
+ An optional keyword-only *context * argument allows specifying a
1053
+ custom :class: `contextvars.Context ` for the *coro * to run in.
1054
+ If no *context * is provided, the Task copies the current context
1055
+ and later runs its coroutine in the copied context.
1055
1056
1056
1057
.. versionchanged :: 3.7
1057
1058
Added support for the :mod: `contextvars ` module.
@@ -1063,6 +1064,9 @@ Task Object
1063
1064
Deprecation warning is emitted if *loop * is not specified
1064
1065
and there is no running event loop.
1065
1066
1067
+ .. versionchanged :: 3.11
1068
+ Added the *context * parameter.
1069
+
1066
1070
.. method :: done()
1067
1071
1068
1072
Return ``True `` if the Task is *done *.
0 commit comments