pyfunctools.decorators.timeout_decorator module
- pyfunctools.decorators.timeout_decorator.timeout_decorator(seconds: int) Callable[[C], C][source]
A decorator that raises a TimeoutError if the decorated function takes longer than a specified time to execute.
- Parameters:
seconds (int) – The maximum allowed time for the function to execute.
- Returns:
The decorated function with timeout control applied.
- Return type:
Callable
Examples
>>> @timeout_decorator(1) ... def func_test(say: str): ... pass >>> >>> func_test('Something') Function func_test timed out after 1 seconds >>> @timeout_decorator(1) ... class MyClass: ... def __init__(self, say: str): ... pass >>> >>> MyClass('Something') Class MyClass timed out after 1 seconds