aea.skills.tasks

This module contains the classes for tasks.

Task

class Task()

This class implements an abstract task.

__init__

 | __init__(**kwargs)

Initialize a task.

__call__

 | __call__(*args, **kwargs)

Execute the task.

Arguments:

  • args: positional arguments forwarded to the 'execute' method.
  • kwargs: keyword arguments forwarded to the 'execute' method. :return the task instance

Raises:

  • ValueError: if the task has already been executed.

is_executed

 | @property
 | is_executed() -> bool

Check if the task has already been executed.

result

 | @property
 | result() -> Any

Get the result.

:return the result from the execute method.

Raises:

  • ValueError: if the task has not been executed yet.

setup

 | @abstractmethod
 | setup() -> None

Implement the behaviour setup.

Returns:

None

execute

 | @abstractmethod
 | execute(*args, **kwargs) -> None

Run the task logic.

Returns:

None

teardown

 | @abstractmethod
 | teardown() -> None

Implement the behaviour teardown.

Returns:

None

init_worker

init_worker() -> None

Initialize a worker.

Disable the SIGINT handler. Related to a well-known bug: https://bugs.python.org/issue8296

Returns:

None

TaskManager

class TaskManager()

A Task manager.

__init__

 | __init__(nb_workers: int = 1, is_lazy_pool_start: bool = True)

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.

is_started

 | @property
 | is_started() -> bool

Get started status of TaskManager.

Returns:

bool

nb_workers

 | @property
 | nb_workers() -> int

Get the number of workers.

Returns:

int

enqueue_task

 | enqueue_task(func: Callable, args: Sequence = (), kwds: Optional[Dict[str, Any]] = None) -> int

Enqueue a task with the executor.

Arguments:

  • func: the callable instance to be enqueued
  • args: the positional arguments to be passed to the function.
  • kwds: the keyword arguments to be passed to the function. :return the task id to get the the result.

Raises:

  • ValueError: if the task manager is not running.

get_task_result

 | get_task_result(task_id: int) -> AsyncResult

Get the result from a task.

Returns:

async result for task_id

start

 | start() -> None

Start the task manager.

Returns:

None

stop

 | stop() -> None

Stop the task manager.

Returns:

None