File tree 1 file changed +17
-4
lines changed
Filter options
1 file changed +17
-4
lines changed
Original file line number Diff line number Diff line change @@ -942,18 +942,31 @@ def callback():
942
942
943
943
944
944
def create_eager_task_factory (custom_task_constructor ):
945
+ """Create a function suitable for use as a task factory on an event-loop.
945
946
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
+ """
949
962
950
963
def factory (loop , coro , * , name = None , context = None ):
951
964
return custom_task_constructor (
952
965
coro , loop = loop , name = name , context = context , eager_start = True )
953
966
954
-
955
967
return factory
956
968
969
+
957
970
eager_task_factory = create_eager_task_factory (Task )
958
971
959
972
You can’t perform that action at this time.
0 commit comments