Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita3d0306

Browse files
authored
gh-128307: Update docs for asyncio.create_task, TaskGroup.create_task, asyncio.create_task (#134202)
1 parent2da2be4 commita3d0306

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

‎Doc/library/asyncio-eventloop.rst

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Creating Futures and Tasks
361361

362362
..versionadded::3.5.2
363363

364-
..method::loop.create_task(coro, *, name=None, context=None, eager_start=None)
364+
..method::loop.create_task(coro, *, name=None, context=None, eager_start=None, **kwargs)
365365

366366
Schedule the execution of:ref:`coroutine<coroutine>` *coro*.
367367
Return a:class:`Task` object.
@@ -370,6 +370,10 @@ Creating Futures and Tasks
370370
for interoperability. In this case, the result type is a subclass
371371
of:class:`Task`.
372372

373+
The full function signature is largely the same as that of the
374+
:class:`Task` constructor (or factory) - all of the keyword arguments to
375+
this function are passed through to that interface.
376+
373377
If the *name* argument is provided and not ``None``, it is set as
374378
the name of the task using:meth:`Task.set_name`.
375379

@@ -388,8 +392,15 @@ Creating Futures and Tasks
388392
..versionchanged::3.11
389393
Added the *context* parameter.
390394

395+
..versionchanged::3.13.3
396+
Added ``kwargs`` which passes on arbitrary extra parameters, including ``name`` and ``context``.
397+
398+
..versionchanged::3.13.4
399+
Rolled back the change that passes on *name* and *context* (if it is None),
400+
while still passing on other arbitrary keyword arguments (to avoid breaking backwards compatibility with 3.13.3).
401+
391402
..versionchanged::3.14
392-
Added the*eager_start* parameter.
403+
All *kwargs* are now passed on. The*eager_start* parameter works with eager task factories.
393404

394405
..method::loop.set_task_factory(factory)
395406

@@ -402,6 +413,16 @@ Creating Futures and Tasks
402413
event loop, and *coro* is a coroutine object. The callable
403414
must pass on all *kwargs*, and return a:class:`asyncio.Task`-compatible object.
404415

416+
..versionchanged::3.13.3
417+
Required that all *kwargs* are passed on to:class:`asyncio.Task`.
418+
419+
..versionchanged::3.13.4
420+
*name* is no longer passed to task factories. *context* is no longer passed
421+
to task factories if it is ``None``.
422+
423+
..versionchanged::3.14
424+
*name* and *context* are now unconditionally passed on to task factories again.
425+
405426
..method::loop.get_task_factory()
406427

407428
Return a task factory or ``None`` if the default one is in use.

‎Doc/library/asyncio-task.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,18 +238,24 @@ Creating Tasks
238238

239239
-----------------------------------------------
240240

241-
..function::create_task(coro, *, name=None, context=None)
241+
..function::create_task(coro, *, name=None, context=None, eager_start=None, **kwargs)
242242

243243
Wrap the *coro*:ref:`coroutine<coroutine>` into a:class:`Task`
244244
and schedule its execution. Return the Task object.
245245

246-
If *name* is not ``None``, it is set as the name of the task using
247-
:meth:`Task.set_name`.
246+
The full function signature is largely the same as that of the
247+
:class:`Task` constructor (or factory) - all of the keyword arguments to
248+
this function are passed through to that interface.
248249

249250
An optional keyword-only *context* argument allows specifying a
250251
custom:class:`contextvars.Context` for the *coro* to run in.
251252
The current context copy is created when no *context* is provided.
252253

254+
An optional keyword-only *eager_start* argument allows specifying
255+
if the task should execute eagerly during the call to create_task,
256+
or be scheduled later. If *eager_start* is not passed the mode set
257+
by:meth:`loop.set_task_factory` will be used.
258+
253259
The task is executed in the loop returned by:func:`get_running_loop`,
254260
:exc:`RuntimeError` is raised if there is no running loop in
255261
current thread.
@@ -290,6 +296,9 @@ Creating Tasks
290296
..versionchanged::3.11
291297
Added the *context* parameter.
292298

299+
..versionchanged::3.14
300+
Added the *eager_start* parameter by passing on all *kwargs*.
301+
293302

294303
Task Cancellation
295304
=================
@@ -330,7 +339,7 @@ and reliable way to wait for all tasks in the group to finish.
330339

331340
..versionadded::3.11
332341

333-
..method::create_task(coro, *, name=None, context=None)
342+
..method::create_task(coro, *, name=None, context=None, eager_start=None, **kwargs)
334343

335344
Create a task in this task group.
336345
The signature matches that of:func:`asyncio.create_task`.
@@ -342,6 +351,10 @@ and reliable way to wait for all tasks in the group to finish.
342351

343352
Close the given coroutine if the task group is not active.
344353

354+
..versionchanged::3.14
355+
356+
Passes on all *kwargs* to:meth:`loop.create_task`
357+
345358
Example::
346359

347360
async def main():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp