Robustfunc provides a set of Python decorators to add common features to existing functions.
Decorator retry can be used to add retrying count to any function. For example:
@retry(3) def func(): pass
If func raises exception, it will be retried up to three times. When the maximum number of retries is met, the exception is bubbled up to the caller.
Decorator throttle can be used to add throttling or flood protection to any function. For example:
@throttle() def func(): pass
By default, throttle allows maximum 20 calls within 2 seconds, with burst support.
It is unfortunately not easy to customize throttle. This is planned for later versions.
Multiple calls to the same function with the same arguments from multiple threads can be merged into one function call with coalesce decorator:
@coalesce() def func(): time.sleep(10) return 42
When func is called from multiple threads, only one invocation is actually made. The return value (or exception) is propagated to other threads.