1919
2020
2121class task :
22- """Decorator class to initialize a `Pipeline` consisting of one task.
22+ """Decorator class to initialize a `Pipeline` consisting of one task, from a function or callable .
2323
24- The behaviour of each task within a Pipeline is determined by the parameters:
25- * `join`: allows the function to take all previous results as input, instead of single results
26- * `concurrency`: runs the functions with multiple (async or threaded) workers
27- * `throttle`: limits the number of results the function is able to produce when all consumers are busy
28- * `bind`: additional args and kwargs to bind to the function when defining a pipeline
24+ Args:
25+ func (callable): A positional-only param defining the task function
26+ join (bool): Allows the task to take all previous results as input, instead of single results
27+ workers (int): Defines the number of workers to run the task
28+ throttle (int): Limits the number of results the task is able to produce when all consumers are busy
29+ multiprocess (bool): Allows the task to be multiprocessed (cannot be `True` for async tasks)
30+ bind (tuple[args, kwargs]): Additional args and kwargs to bind to the task when defining a pipeline
31+
32+ Returns:
33+ Pipeline: A `Pipeline` instance consisting of one task.
34+
35+ Example:
36+ ```python
37+ def f(x: int):
38+ return x + 1
39+
40+ p = task(f, workers=10, multiprocess=True)
41+ ```
2942 """
3043 @t .overload
3144 def __new__ (
@@ -34,7 +47,7 @@ def __new__(
3447 / ,
3548 * ,
3649 join : bool = False ,
37- concurrency : int = 1 ,
50+ workers : int = 1 ,
3851 throttle : int = 0 ,
3952 multiprocess : bool = False ,
4053 bind : _ArgsKwargs = None ) -> t .Type [task ]: ...
@@ -46,7 +59,7 @@ def __new__(
4659 / ,
4760 * ,
4861 join : bool = False ,
49- concurrency : int = 1 ,
62+ workers : int = 1 ,
5063 throttle : int = 0 ,
5164 multiprocess : bool = False ,
5265 bind : _ArgsKwargs = None ) -> AsyncPipeline [_P , _R ]: ...
@@ -58,7 +71,7 @@ def __new__(
5871 / ,
5972 * ,
6073 join : bool = False ,
61- concurrency : int = 1 ,
74+ workers : int = 1 ,
6275 throttle : int = 0 ,
6376 multiprocess : bool = False ,
6477 bind : _ArgsKwargs = None ) -> AsyncPipeline [_P , _R ]: ...
@@ -70,7 +83,7 @@ def __new__(
7083 / ,
7184 * ,
7285 join : bool = False ,
73- concurrency : int = 1 ,
86+ workers : int = 1 ,
7487 throttle : int = 0 ,
7588 multiprocess : bool = False ,
7689 bind : _ArgsKwargs = None ) -> Pipeline [_P , _R ]: ...
@@ -82,7 +95,7 @@ def __new__(
8295 / ,
8396 * ,
8497 join : bool = False ,
85- concurrency : int = 1 ,
98+ workers : int = 1 ,
8699 throttle : int = 0 ,
87100 multiprocess : bool = False ,
88101 bind : _ArgsKwargs = None ) -> Pipeline [_P , _R ]: ...
@@ -93,14 +106,14 @@ def __new__(
93106 / ,
94107 * ,
95108 join : bool = False ,
96- concurrency : int = 1 ,
109+ workers : int = 1 ,
97110 throttle : int = 0 ,
98111 multiprocess : bool = False ,
99112 bind : _ArgsKwargs = None ):
100113 # Classic decorator trick: @task() means func is None, @task without parentheses means func is passed.
101114 if func is None :
102- return functools .partial (cls , join = join , concurrency = concurrency , throttle = throttle , multiprocess = multiprocess , bind = bind )
103- return Pipeline ([Task (func = func , join = join , concurrency = concurrency , throttle = throttle , multiprocess = multiprocess , bind = bind )])
115+ return functools .partial (cls , join = join , workers = workers , throttle = throttle , multiprocess = multiprocess , bind = bind )
116+ return Pipeline ([Task (func = func , join = join , workers = workers , throttle = throttle , multiprocess = multiprocess , bind = bind )])
104117
105118 @staticmethod
106119 def bind (* args , ** kwargs ) -> _ArgsKwargs :
@@ -113,6 +126,7 @@ def f(x: int, y: int):
113126
114127 p = task(f, bind=task.bind(y=1))
115128 p(x=1)
129+ ```
116130 """
117131 if not args and not kwargs :
118132 return None
0 commit comments