HWRF
trunk@4391
|
Contains retry_io() which automates retrying operations. More...
Contains retry_io() which automates retrying operations.
Functions | |
def | retry_io |
This function automates retrying an unreliable operation several times until it succeeds. More... | |
Variables | |
list | __all__ = ['retry_io'] |
Symbols exported by "from produtil.retry import *". | |
def produtil.retry.retry_io | ( | max_tries, | |
sleep_time, | |||
operation, | |||
opargs = [] , |
|||
logger = None , |
|||
fail = None , |
|||
failargs = [] , |
|||
giveup = None , |
|||
giveupargs = [] , |
|||
randsleep = True , |
|||
backoff = 1.3 , |
|||
first_warn = 0 , |
|||
giveup_quiet = False |
|||
) |
This function automates retrying an unreliable operation several times until it succeeds.
This subroutine will retry the operation up to a maximum number of times. If the operation fails too many times, then the last exception thrown by the operation is passed on (raised) to the caller.
max_tries | Maximum number of times to attempt the operation (mandatory) |
sleep_time | Time to sleep between tries |
operation | A function or callable object that may thrown an Exception |
opargs | A list containing arguments to the operation |
logger | A logging.Logger object to use for logging, or None to disable logging. |
fail | A string to print, or a function to call, when the operation fails but more retries are possible |
failargs | Optional: a list of arguments to fail, or None to disable |
giveup | A string to print, or a function to call when the operation fails too many times, causing retry_io to give up. Default: same as fail |
giveupargs | Optional: a list of arguments to giveup, or None to disable |
randsleep | Set to True (default) to enable an exponential backoff algorithm, which will increase the sleep time between tries |
backoff | The exponent for the exponential backoff algorithm |
first_warn | The first failure at which to warn via the logger |
giveup_quiet | If True, a WARNING-level message is sent to the logger if the operation fails more than max_tries times. |