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

Commitbf89d42

Browse files
authored
gh-97696 Remove unnecessary check for eager_start kwarg (#104188)
Instead, add docstring to create_eager_task_factory.
1 parentfaf1962 commitbf89d42

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

‎Lib/asyncio/tasks.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -942,18 +942,31 @@ def callback():
942942

943943

944944
defcreate_eager_task_factory(custom_task_constructor):
945+
"""Create a function suitable for use as a task factory on an event-loop.
945946
946-
if"eager_start"notininspect.signature(custom_task_constructor).parameters:
947-
raiseTypeError(
948-
"Provided constructor does not support eager task execution")
947+
Example usage:
948+
949+
loop.set_task_factory(
950+
asyncio.create_eager_task_factory(my_task_constructor))
951+
952+
Now, tasks created will be started immediately (rather than being first
953+
scheduled to an event loop). The constructor argument can be any callable
954+
that returns a Task-compatible object and has a signature compatible
955+
with `Task.__init__`; it must have the `eager_start` keyword argument.
956+
957+
Most applications will use `Task` for `custom_task_constructor` and in
958+
this case there's no need to call `create_eager_task_factory()`
959+
directly. Instead the global `eager_task_factory` instance can be
960+
used. E.g. `loop.set_task_factory(asyncio.eager_task_factory)`.
961+
"""
949962

950963
deffactory(loop,coro,*,name=None,context=None):
951964
returncustom_task_constructor(
952965
coro,loop=loop,name=name,context=context,eager_start=True)
953966

954-
955967
returnfactory
956968

969+
957970
eager_task_factory=create_eager_task_factory(Task)
958971

959972

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp