File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Open diff view settings
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Open diff view settings
Original file line number Diff line number Diff line change @@ -942,18 +942,31 @@ def callback():
942942
943943
944944def create_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" not in inspect .signature (custom_task_constructor ).parameters :
947- raise TypeError (
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 def factory (loop , coro , * , name = None , context = None ):
951964 return custom_task_constructor (
952965 coro , loop = loop , name = name , context = context , eager_start = True )
953966
954-
955967 return factory
956968
969+
957970eager_task_factory = create_eager_task_factory (Task )
958971
959972
You can’t perform that action at this time.
0 commit comments