decorators
Decorators of Tawazi.
The user should use the decorators @dag
and @xn
to create Tawazi objects DAG
and ExecNode
.
xn(func=None, *, priority=0, is_sequential=cfg.TAWAZI_IS_SEQUENTIAL, debug=False, tag=None, setup=False, unpack_to=None, resource=cfg.TAWAZI_DEFAULT_RESOURCE)
¶
Decorate a normal function to make it an ExecNode.
When the decorated function is called inside a DAG
, you are actually calling an ExecNode
.
This way we can record the dependencies in order to build the actual DAG.
Please check the example in the README for a guide to the usage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
[Callable[P, RVXN]
|
a Callable that will be executed in the |
None
|
priority |
int
|
priority of the execution with respect to other |
0
|
is_sequential |
bool
|
whether to allow the execution of this |
cfg.TAWAZI_IS_SEQUENTIAL
|
debug |
bool
|
if |
False
|
tag |
Optional[TagOrTags]
|
a str or Tuple[str] to tag this ExecNode. If Tuple[str] is given, every value of the tuple is used as tag. Notice that multiple ExecNodes can have the same tag. |
None
|
setup |
bool
|
if True, will be executed only once during the lifetime of a |
False
|
unpack_to |
Optional[int]
|
if not None, this ExecNode's execution must return unpacked results corresponding to the given value |
None
|
resource |
str
|
the resource to use to execute this ExecNode. Defaults to "thread". |
cfg.TAWAZI_DEFAULT_RESOURCE
|
Returns:
Name | Type | Description |
---|---|---|
LazyExecNode |
Union[Callable[[Callable[P, RVXN]], LazyExecNode[P, RVXN]], LazyExecNode[P, RVXN]]
|
The decorated function wrapped in an |
Raises:
Type | Description |
---|---|
TypeError
|
If the decorated function passed is not a |
Source code in tawazi/_decorators.py
dag(declare_dag_function=None, *, max_concurrency=1, behavior=ErrorStrategy.strict)
¶
Transform the declared ExecNode
s into a DAG that can be executed by Tawazi's scheduler.
The same DAG can be executed multiple times.
dag is thread safe because it uses an internal lock.
If you need to construct lots of DAGs in multiple threads, it is best to construct your dag once and then use it as much as you like.
Please check the example in the README for a guide to the usage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
declare_dag_function |
Optional[Callable[P, RVDAG]]
|
a function that describes the execution of the DAG.
This function should only contain calls to |
None
|
max_concurrency |
int
|
the maximum number of concurrent threads to execute in parallel. |
1
|
behavior |
ErrorStrategy
|
the behavior of the |
ErrorStrategy.strict
|
Returns:
Type | Description |
---|---|
Union[Callable[[Callable[P, RVDAG]], DAG[P, RVDAG]], DAG[P, RVDAG]]
|
a |
Raises:
Type | Description |
---|---|
TypeError
|
If the decorated object is not a Callable. |
Source code in tawazi/_decorators.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|