apply_timeout
Executes a target function within a specified time limit, returning the result of the target or invoking a timeout callback if the duration is exceeded.
def apply_timeout(
target: callable,
args: tuple,
kwargs: dict,
callback: callable,
accept_callback: callable,
getpid: callable,
timeout: float,
timeout_callback: callable,
Timeout: Exception,
apply_target: callable
) - > Any
Executes a target function within a specified time limit and handles potential timeout exceptions via a callback.
Parameters
| Name | Type | Description |
|---|---|---|
| target | callable | The function or task to be executed. |
| args | tuple | Positional arguments to pass to the target function. |
| kwargs | dict | Keyword arguments to pass to the target function. |
| callback | callable | Function to be invoked upon successful completion of the target. |
| accept_callback | callable | Function to be invoked when the task is accepted for execution. |
| getpid | callable | A function that returns the process ID associated with the execution. |
| timeout | float | The maximum duration in seconds allowed for the target function to run. |
| timeout_callback | callable | Function invoked if the execution exceeds the timeout limit; it receives the success status and timeout value. |
| Timeout | Exception | The exception class used to manage and catch timeout events. |
| apply_target | callable | The underlying execution wrapper used to invoke the target with the provided context. |
Returns
| Type | Description |
|---|---|
Any | The result of the target function if successful, or the result of the timeout_callback if the time limit is exceeded. |