openfl.utilities.fed_timer.PrepareTask

class openfl.utilities.fed_timer.PrepareTask(target_fn, timeout, args, kwargs)

Bases: object

PrepareTask class stores the decorated function metadata and instantiates either the asyncio or thread tasks to handle asynchronous and synchronous execution of the decorated function respectively.

Attributes: target (function): decorated function timeout (int): Timeout duration in second(s). *args (tuple): Arguments passed as a parameter to decorated function. **kwargs (dict): Keyword arguments passed as a parameter to decorated function.

Methods

async_execute

Execute the task asynchronously of the decorated function referenced by self._target_fn.

sync_execute

Handles synchronous execution of the decorated function referenced by self._target_fn.

async async_execute()

Execute the task asynchronously of the decorated function referenced by self._target_fn.

Raises:
  • asyncio.TimeoutError – If the execution exceeds the maximum time.

  • Exception – If any other error occurs during execution.

Returns:

Any – The result of the function’s execution. The returned value from task.results() depends on the decorated function.

sync_execute()

Handles synchronous execution of the decorated function referenced by self._target_fn.

Raises:

TimeoutError – If the execution exceeds the maximum time.

Returns:

Any – The returned value from task.results() depends on the decorated function.