aea.skills.tasks
This module contains the classes for tasks.
Task Objects
This class implements an abstract task.
__init__
Initialize a task.
__call__
Execute the task.
Arguments:
args: positional arguments forwarded to the 'execute' method.kwargs: keyword arguments forwarded to the 'execute' method.
Returns:
the task instance
Raises:
ValueError: if the task has already been executed.
is_executed
Check if the task has already been executed.
result
Get the result.
Returns:
the result from the execute method.
Raises:
ValueError: if the task has not been executed yet.
setup
Implement the task setup.
execute
Run the task logic.
Arguments:
args: the positional argumentskwargs: the keyword arguments
Returns:
any
teardown
Implement the task teardown.
init_worker
Initialize a worker.
Disable the SIGINT handler of process pool is using. Related to a well-known bug: https://bugs.python.org/issue8296
TaskManager Objects
A Task manager.
__init__
| __init__(nb_workers: int = DEFAULT_WORKERS_AMOUNT, is_lazy_pool_start: bool = True, logger: Optional[logging.Logger] = None, pool_mode: str = THREAD_POOL_MODE) -> None
Initialize the task manager.
Arguments:
nb_workers: the number of worker processes.is_lazy_pool_start: option to postpone pool creation till the first enqueue_task called.logger: the logger.pool_mode: str. multithread or multiprocess
is_started
Get started status of TaskManager.
Returns:
bool
nb_workers
Get the number of workers.
Returns:
int
enqueue_task
Enqueue a task with the executor.
Arguments:
func: the callable instance to be enqueuedargs: the positional arguments to be passed to the function.kwargs: the keyword arguments to be passed to the function.
Returns:
the task id to get the the result.
Raises:
ValueError: if the task manager is not running.
get_task_result
Get the result from a task.
Arguments:
task_id: the task id
Returns:
async result for task_id
start
Start the task manager.
stop
Stop the task manager.
ThreadedTaskManager Objects
A threaded task manager.
__init__
| __init__(nb_workers: int = DEFAULT_WORKERS_AMOUNT, is_lazy_pool_start: bool = True, logger: Optional[logging.Logger] = None) -> None
Initialize the task manager.
Arguments:
nb_workers: the number of worker processes.is_lazy_pool_start: option to postpone pool creation till the first enqueue_task called.logger: the logger.
ProcessTaskManager Objects
A multiprocess task manager.
__init__
| __init__(nb_workers: int = DEFAULT_WORKERS_AMOUNT, is_lazy_pool_start: bool = True, logger: Optional[logging.Logger] = None) -> None
Initialize the task manager.
Arguments:
nb_workers: the number of worker processes.is_lazy_pool_start: option to postpone pool creation till the first enqueue_task called.logger: the logger.