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.
Raises:
ValueError
: if the task has already been executed.
Returns:
the task instance
is_
executed¶
Check if the task has already been executed.
result¶
Get the result.
Raises:
ValueError
: if the task has not been executed yet.
Returns:
the result from the execute method.
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__
¶
def __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¶
def enqueue_task(func: Callable,
args: Sequence = (),
kwargs: Optional[Dict[str, Any]] = None) -> int
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.
Raises:
ValueError
: if the task manager is not running.
Returns:
the task id to get the the result.
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__
¶
def __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__
¶
def __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.