-
Notifications
You must be signed in to change notification settings - Fork 5
Retry decorator
Roberto Prevato edited this page Sep 22, 2019
·
3 revisions
from essentials.decorators import retry
@retry()
def function_that_supports_automatic_retries():
# do something...
pass
@retry()
async def async_function_that_supports_automatic_retries():
# do await something...
pass
Options: in the example below, a function is retried up to 5 times, with a delay of 0.5 s between retries, and catching only a specific type of exception, for example MyKindOfException
.
from essentials.decorators import retry
# example: try again up to 5 times, with a delay of 0.5 s between retries,
@retry(times=5, delay=0.5, catch_exceptions_types=MyKindOfException)
def function_that_supports_automatic_retries():
# do something...
pass