ó ‹÷Îgc @s^dZdgZddlZddlZddlZgddgdgedded„ ZdS(s9!Contains retry_io() which automates retrying operations.tretry_ioiÿÿÿÿNgÍÌÌÌÌÌô?ic  Css|dk r9|dkr!|}n|dkr9|}q9n|dk r]|dkr]|}q]n|dkrrd}n|} xôt|ƒD]æ}y@|dk rÀ|jdt|ƒt|ƒfƒn||ŒSWq…tk rj}||dkrI|dk r|jdt|ƒfdtƒn|dk rs| rst|dƒttd| |ƒdƒ}t j |d |ƒ} qsnt |tƒrÊ|dk r0|| kr0|j d ||d|| t|ƒfƒq0nf|dk r0|}|j ||d||tgƒ|dk r#|jd t|ƒƒn||Œntjtd| ƒƒqk|dk rx|jd t|ƒfdtƒnt |tƒrÊ| rÊ|dk rd|jd ||dt|ƒfdtƒqdnš|dk rd|}|j ||d||tgƒ|dk r#|jdt|ƒƒnt |tƒrW| ra|dk ra|j|ƒqaqd||Œn‚q…Xq…WdS(s>!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. @param max_tries Maximum number of times to attempt the operation (mandatory) @param sleep_time Time to sleep between tries @param operation A function or callable object that may thrown an Exception @param opargs A list containing arguments to the operation @param logger A logging.Logger object to use for logging, or None to disable logging. @param fail A string to print, or a function to call, when the operation fails but more retries are possible @param failargs Optional: a list of arguments to fail, or None to disable @param 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 @param giveupargs Optional: a list of arguments to giveup, or None to disable @param randsleep Set to True (default) to enable an exponential backoff algorithm, which will increase the sleep time between tries @param backoff The exponent for the exponential backoff algorithm @param first_warn The first failure at which to warn via the logger @param giveup_quiet If True, a WARNING-level message is sent to the logger if the operation fails more than max_tries times. @return The return value of the operation. @note If fail or giveup are functions, they are passed the contents of failargs (default: opargs) or giveupargs (default: failargs or opargs) with several additional arguments appended. Those arguments are the exception that was caught, the number of attempts so far, the max_tries, the sleep_time, and then a boolean that is true iff the operation is about to be retried.gš™™™™™¹?s%s(%s)is Failed but have not given up: %stexc_infogš™™™™™©?gð?gI@g@s(%s (try %d/%d; sleep %.3f and retry): %ssarglist to fail (1): sFailed and gave up: %ss!%s (giving up after %d tries): %ssarglist to fail (2): N(tNonetrangetdebugtreprt ExceptiontstrtTruetmintmaxtrandomtuniformt isinstancetinfotextendttimetsleeptwarningtFalse(t max_triest sleep_timet operationtopargstloggertfailtfailargstgiveupt giveupargst randsleeptbackofft first_warnt giveup_quiettsleepmetntrytetsleepmaxtarglist((s;/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/retry.pyR sl%        &     '        '    ( t__doc__t__all__RtloggingR RRRR(((s;/lfs/h1/ops/prod/packages/hafs.v2.0.7/ush/produtil/retry.pyts