osnapi/core.py
def retry_on(EX:Exception, retries:int=1, on_failure:Callable=None): # TODO(florian): test that on_failure returns a boolean?
    """Decorator that retries the decorated function n (retries) times,
       calling on_failure each time it fails with a given Exception EX.
       EX can be one, or a tuple of Exception/s that should be caught.
       on_failure takes the Exception that caused the failure,
       and returns a boolean saying whether or not to try again."""
    assert retries >= 0, 'can\'t have negative retries'
    if on_failure is None: on_failure = lambda e: True
    def _retry_on(func):
        def _wrapper(*args, **kwargs):
            retry, _tries, _e = True, retries + 1, Exception('Something went wrong in retry_on()')
            while (retry and (_tries > 0)):
                retry, _tries = False, _tries - 1
                try: return func(*args, **kwargs)
                except EX as e: _e, retry = e, on_failure(e) # TODO(florian): also pass the repeat count / args / kwargs?
            else: raise _e
        return _wrapper
    return _retry_on
Decorator that retries the decorated function n (retries) times,
       calling on_failure each time it fails with a given Exception EX.
       EX can be one, or a tuple of Exception/s that should be caught.
       on_failure takes the Exception that caused the failure,
       and returns a boolean saying whether or not to try again.
Decorator that retries the decorated function n (retries) times,
calling on_failure each time it fails with a given Exception EX.
EX can be one, or a tuple of Exception/s that should be caught.
on_failure takes the Exception that caused the failure,
and returns a boolean saying whether or not to try again.
Decorator that retries the decorated function n ( retries ) times calling on_failure each time it fails with a given Exception EX . EX can be one or a tuple of Exception / s that should be caught . on_failure takes the Exception that caused the failure and returns a boolean saying whether or not to try again .
def retry_on(EX:Exception, retries:int=1, on_failure:Callable=None): 
    assert retries >= 0, 'can\'t have negative retries'
    if on_failure is None: on_failure = lambda e: True
    def _retry_on(func):
        def _wrapper(*args, **kwargs):
            retry, _tries, _e = True, retries + 1, Exception('Something went wrong in retry_on()')
            while (retry and (_tries > 0)):
                retry, _tries = False, _tries - 1
                try: return func(*args, **kwargs)
                except EX as e: _e, retry = e, on_failure(e) 
            else: raise _e
        return _wrapper
    return _retry_on
def retry_on ( EX : Exception , retries : int = 1 , on_failure : Callable = None ) : assert retries >= 0 , 'can\'t have negative retries' if on_failure is None : on_failure = lambda e : True def _retry_on ( func ) : def _wrapper ( * args , ** kwargs ) : retry , _tries , _e = True , retries + 1 , Exception ( 'Something went wrong in retry_on()' ) while ( retry and ( _tries > 0 ) ) : retry , _tries = False , _tries - 1 try : return func ( * args , ** kwargs ) except EX as e : _e , retry = e , on_failure ( e ) else : raise _e return _wrapper return _retry_on
Decorator that retries the decorated function n (retries) times,
calling on_failure each time it fails with a given Exception EX.
Decorator that retries the decorated function n ( retries ) times calling on_failure each time it fails with a given Exception EX .
# TODO(florian): test that on_failure returns a boolean? """Decorator that retries the decorated function n (retries) times,
       calling on_failure each time it fails with a given Exception EX.
       EX can be one, or a tuple of Exception/s that should be caught.
       on_failure takes the Exception that caused the failure,
       and returns a boolean saying whether or not to try again.""" # TODO(florian): also pass the repeat count / args / kwargs?
EX
Exception
retries
int
on_failure
Callable