<s> import logging <EOL> import random <EOL> import time <EOL> from functools import partial <EOL> from retry . compat import decorator <EOL> logging_logger = logging . getLogger ( __name__ ) <EOL> def __retry_internal ( f , exceptions = Exception , tries = - <NUM_LIT:1> , delay = <NUM_LIT:0> , max_delay = None , backoff = <NUM_LIT:1> , jitter = <NUM_LIT:0> , <EOL> logger = logging_logger ) : <EOL> """<STR_LIT>""" <EOL> _tries , _delay = tries , delay <EOL> while _tries : <EOL> try : <EOL> return f ( ) <EOL> except exceptions as e : <EOL> _tries -= <NUM_LIT:1> <EOL> if not _tries : <EOL> raise <EOL> if logger is not None : <EOL> logger . warning ( '<STR_LIT>' , e , _delay ) <EOL> time . sleep ( _delay ) <EOL> _delay *= backoff <EOL> if isinstance ( jitter , tuple ) : <EOL> _delay += random . uniform ( * jitter ) <EOL> else : <EOL> _delay += jitter <EOL> if max_delay is not None : <EOL> _delay = min ( _delay , max_delay ) <EOL> def retry ( exceptions = Exception , tries = - <NUM_LIT:1> , delay = <NUM_LIT:0> , max_delay = None , backoff = <NUM_LIT:1> , jitter = <NUM_LIT:0> , logger = logging_logger ) : <EOL> """<STR_LIT>""" <EOL> @ decorator <EOL> def retry_decorator ( f , * fargs , ** fkwargs ) : <EOL> args = fargs if fargs else list ( ) <EOL> kwargs = fkwargs if fkwargs else dict ( ) <EOL> return __retry_internal ( partial ( f , * args , ** kwargs ) , exceptions , tries , delay , max_delay , backoff , jitter , <EOL> logger ) <EOL> return retry_decorator <EOL> def retry_call ( f , fargs = None , fkwargs = None , exceptions = Exception , tries = - <NUM_LIT:1> , delay = <NUM_LIT:0> , max_delay = None , backoff = <NUM_LIT:1> , <EOL> jitter = <NUM_LIT:0> , <EOL> logger = logging_logger ) : <EOL> """<STR_LIT>""" <EOL> args = fargs if fargs else list ( ) <EOL> kwargs = fkwargs if fkwargs else dict ( ) <EOL> return __retry_internal ( partial ( f , * args , ** kwargs ) , exceptions , tries , delay , max_delay , backoff , jitter , logger ) </s>
