OpenFL Component Timeouts
This feature allows decorating any arbitrary synchronous and/or asynchronous functions using
The decorated functions is then monitored and gets terminated right after the execution time exceeds the user specified or default timeout value.
The fedtiming class, SyncAsyncTaskDecoFactory factory class, custom synchronous and asynchronous execution of decorated function is in-place. The end to end implementation of OpenFL Component timeouts feature is still in beta mode and would undergo design and implementation changes before the complete feature is made available. Appreciate any feedbacks or issues.
An overview of this workflow is shown below.
- class center
- Overview of the component timeout class diagram
Flow of execution
[Step A] Decorate any sync or async function
@fedtiming(timeout=<seconds>)to monitor its execution time and terminate after timeout=<seconds> value.
@fedtiming(timeout=5) def some_sync_function(): passThis decorated function execution gets terminated after 5 seconds.
@fedtiming(timeout=10) async def some_async_function(): await some_long_running_operation()This decorated function execution gets terminated after 10 seconds.
[Step B] Concrete fedtiming class:
During Compile time: Decorated functions are evaluated like below.
some_sync_function = fedtiming(timeout=5)(some_sync_function) then some_sync_function() *is equivalent to* sync_wrapper().
inside the sync_wrapper: the decorated function some_sync_function and timeout variables are stored as a closure variable.
some_async_function = fedtiming(timeout=5)(some_async_function) then some_async_function() *is equivalent to* async_wrapper().
inside the async_wrapper: the decorated function some_async_function and timeout variables are stored as a closure variable.
[Step C] SyncAsyncTaskDecoFactory class
fedtiming(some_sync_function) internally calls the parent class SyncAsyncTaskDecoFactory
__call__()method immediately returns either the sync_wrapper or async_wrapper depending on whether the sync or async method was decorated.
The prepared some_sync_function or some_async_function when called internally with its respective parameters.
some_sync_function(*args, **kwargs) -> sync_wrapper(*args, **kwargs) some_async_function(*args, **kwargs) -> async_wrapper(*args, **kwargs)
[Step D] PrepareTask class
Delegates the decorated sync or async function to be executed synchronously or asynchronously using CustomThread or asyncio.
Contains the defination for the function sync_execute and async_execute.
[Step E] Execution of delegated methods:
The delegated function is executed synchronously or asynchronously and the result is returned back in the call chain. The final output from the thread or asyncio task is returned as a result of a decorated function execution.
In this CustomThread or asyncio.wait_for() execution, the timeout is enforced which terminates the running function after a set period of time and an exception is called that tracebacks to the caller.
Above design reflects current implementation.
Upcoming changes include:
Dynamic timeout parameters updates for all decorated functions during runtime. Removal of timeout parameter @fedtiming(timeout=<?>).
Add a callback parameter that defines a post timeout teardown logic and a way gracefully terminate executing function.