decorators
_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 |
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". |
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 |
dag(declare_dag_function=None, *, max_concurrency=1, is_async=False)
¶
Transform the declared ExecNode
s into a DAG that can be executed by Tawazi's scheduler.
The same DAG can be executed multiple times. Note: 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
|
is_async |
bool
|
if True, the returned object will be an |
False
|
Returns:
Type | Description |
---|---|
Union[DAG[P, RVDAG], AsyncDAG[P, RVDAG], Callable[[Callable[P, RVDAG]], Union[DAG[P, RVDAG], AsyncDAG[P, RVDAG]]]]
|
a |
Raises:
Type | Description |
---|---|
TypeError
|
If the decorated object is not a Callable. |