openfl.utilities.fed_timer.PrepareTask#
- class openfl.utilities.fed_timer.PrepareTask(target_fn, timeout, args, kwargs)[source]#
Bases:
objectPrepareTask 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.
- __init__(target_fn, timeout, args, kwargs)[source]#
Initialize a PrepareTask object.
- Parameters:
target_fn (function) – The function to be executed.
timeout (int) – The maximum time to allow for the function’s execution.
args (tuple) – The positional arguments to pass to the function.
kwargs (dict) – The keyword arguments to pass to the function.
- Return type:
None
Methods
__init__(target_fn, timeout, args, kwargs)Initialize a PrepareTask object.
Execute the task asynchronously of the decorated function referenced by self._target_fn.
Handles synchronous execution of the decorated function referenced by self._target_fn.
- async async_execute()[source]#
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:
- The result of the function’s execution.
The returned value from task.results() depends on the decorated function.
- Return type:
Any