Retries a function or method until it got True.

    - ``delay`` sets the initial delay in seconds
    - ``back_off`` sets the factor by which
    - ``raise_msg`` if not '', it'll raise an Exception
176132
def retry(tries, delay=0, back_off=1, raise_msg=''):
    

    if back_off < 1:
        raise ValueError('back_off must be 1 or greater')

    tries = math.floor(tries)
    if tries < 0:
        raise ValueError('tries must be 0 or greater')

    if delay < 0:
        raise ValueError('delay must be 0 or greater')

    def deco_retry(f):
        def f_retry(*args, **kwargs):
            max_tries, max_delay = tries, delay  # make mutable

            while max_tries > 0:
                rv = f(*args, **kwargs)  # first attempt
                if rv:  # Done on success
                    return rv

                max_tries -= 1  # consume an attempt
                time.sleep(max_delay)  # wait...
                max_delay *= back_off  # make future wait longer
            else:
                if raise_msg:
                    raise Exception(raise_msg)
                return

        return f_retry  # true decorator -> decorated function

    return deco_retry
177742
def raise_on_error(f):
    

    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        result = f(*args, **kwargs)
        retcode = GetLastError()
        if retcode and retcode != ERROR_IO_PENDING:
            err = WinError(code=retcode)
            windll.kernel32.SetLastError(0)  # clear error code so that we don't raise twice.
            raise err
        return result

    return wrapper
405443
def call_with_retry(func: Callable, exceptions, max_retries: int,
                    logger: Logger, *args, **kwargs):
    """"""
    attempt = 0
    while True:
        try:
            return func(*args, **kwargs)
        except exceptions as e:
            attempt += 1
            if attempt >= max_retries:
                raise

            delay = exponential_backoff(attempt, cap=60)
            logger.warning('%s: retrying in %s', e, delay)
            time.sleep(delay.total_seconds())
1348541
def retry(tries=10, delay=1, backoff=2, retry_exception=None):
    
    assert tries > 0, "tries must be 1 or greater"
    catching_mode = bool(retry_exception)

    def deco_retry(f):
        @functools.wraps(f)
        def f_retry(*args, **kwargs):
            mtries, mdelay = tries, delay

            while mtries > 0:
                time.sleep(mdelay)
                mdelay *= backoff
                try:
                    rv = f(*args, **kwargs)
                    if not catching_mode and rv:
                        return rv
                except retry_exception:
                    pass
                else:
                    if catching_mode:
                        return rv
                mtries -= 1
                if mtries is 0 and not catching_mode:
                    return False
                if mtries is 0 and catching_mode:
                    return f(*args, **kwargs)  # extra try, to avoid except-raise syntax
                log.debug("{0} try, sleeping for {1} sec".format(tries-mtries, mdelay))
            raise Exception("unreachable code")
        return f_retry
    return deco_retry
335008
def retry(*dargs, **dkw):
    
    # support both @retry and @retry() as valid syntax
    if len(dargs) == 1 and callable(dargs[0]):
        def wrap_simple(f):

            @six.wraps(f)
            def wrapped_f(*args, **kw):
                return Retrying().call(f, *args, **kw)

            return wrapped_f

        return wrap_simple(dargs[0])

    else:
        def wrap(f):

            @six.wraps(f)
            def wrapped_f(*args, **kw):
                return Retrying(*dargs, **dkw).call(f, *args, **kw)

            return wrapped_f

        return wrap
446637
def retry_call(func, cleanup=lambda: None, retries=0, trap=()):
	
	attempts = count() if retries == float('inf') else range(retries)
	for attempt in attempts:
		try:
			return func()
		except trap:
			cleanup()

	return func()
231349
def defer_sync(self, func):
        
        latch = Latch()
        def wrapper():
            try:
                latch.put(func())
            except Exception:
                latch.put(sys.exc_info()[1])
        self.defer(wrapper)
        res = latch.get()
        if isinstance(res, Exception):
            raise res
        return res
241362
def delay(self, seconds=0, minutes=0, msg=None):
        
        delay_time = seconds + minutes * 60
        self._hw_manager.hardware.delay(delay_time)
540140
def stop_func_accept_retry_state(stop_func):
    """"""
    if not six.callable(stop_func):
        return stop_func

    if func_takes_retry_state(stop_func):
        return stop_func

    @_utils.wraps(stop_func)
    def wrapped_stop_func(retry_state):
        warn_about_non_retry_state_deprecation(
            'stop', stop_func, stacklevel=4)
        return stop_func(
            retry_state.attempt_number,
            retry_state.seconds_since_start,
        )
    return wrapped_stop_func
1210634
function(callback, delay, repetitions) {
  var x = 0;
  var intervalID = setInterval(function () {
    if (++x === repetitions) {
      clearInterval(intervalID);
      receive_interval_timer = false;
    }
    callback();
  }, delay);
  return intervalID;
}
912455
async function retryPromise(fn, attempts, backoff) {
    let aborted = false;

    try {
        const data = await fn(() => { aborted = true; });
        return data;
    }
    catch (e) {
        if (aborted || ((backoff.attempts + 1) >= attempts)) {
            throw e;
        }

        const duration = backoff.duration();
        debug(`Promise rejected attempt #${backoff.attempts}, retrying in ${duration}ms: ${e.message}`);

        await Promise.delay(duration);
        return retryPromise(fn, attempts, backoff);
    }
}
565106
def retry_on_signal(function):
    """"""
    while True:
        try:
            return function()
        except EnvironmentError, e:
            if e.errno != errno.EINTR:
                raise
1113897
def wait_for_fun(fun, timeout=900, **kwargs):
    '''
    
    '''
    start = time.time()
    log.debug('Attempting function %s', fun)
    trycount = 0
    while True:
        trycount += 1
        try:
            response = fun(**kwargs)
            if not isinstance(response, bool):
                return response
        except Exception as exc:
            log.debug('Caught exception in wait_for_fun: %s', exc)
            time.sleep(1)
            log.debug('Retrying function %s on  (try %s)', fun, trycount)
        if time.time() - start > timeout:
            log.error('Function timed out: %s', timeout)
            return False
76253
function retry(promise, fn, opts) {

  // Piggy back off of previous promise.
  return promise.then(function() {

    // Setup default options.
    opts = opts || {};
    opts.max = opts.max || 5;
    opts.backoff = opts.backoff || 500;

    // Recursive function.
    var rec = function(counter) {

      // Call function fn within the context of a Promise.
      return Promise.try(function() {
        return fn(counter);
      })
      // Handle errors.
      .catch(function(err) {

        // If we haven't reached max retries, delay for a short while and
        // then retry.
        if (counter < opts.max) {

          return Promise.delay(opts.backoff * counter)
          .then(function() {
            return rec(counter + 1);
          });

        } else {

          // No retries left so wrap and throw the error.
          throw new VError(
            err,
            'Failed after %s retries. %s',
            opts.max,
            JSON.stringify(opts)
          );

        }
      });

    };

    // Init recursive function.
    return rec(1);

  });

}
604183
private function backOff()
  {
    $delay = $this->getDelay();

    $this->client->getLogger()->debug(
        'Retrying task with backoff',
        array(
            'request' => $this->name,
            'retry' => $this->attempts,
            'backoff_seconds' => $delay
        )
    );

    usleep($delay * 1000000);
  }
788964
function retry() {
    if (!self.waitInterval) {
      setImmediate(function() {
        self._read(size);
      });
    } else {
      setTimeout(function() {
        self._read(size);
      }, self.waitInterval * Math.random()).unref();
    }
  }
964441
def retry(tries, delay=3, backoff=2):
    """"""

    if backoff <= 1:
        raise ValueError("backoff must be greater than 1")

    tries = math.floor(tries)
    if tries < 0:
        raise ValueError("tries must be 0 or greater")

    if delay <= 0:
        raise ValueError("delay must be greater than 0")

    def deco_retry(f):
        def f_retry(*args, **kwargs):
            mtries, mdelay = tries, delay

            rv = f(*args, **kwargs)  # first attempt
            while mtries > 0:
                if rv is True:
                    return True

                mtries -= 1
                time.sleep(mdelay)
                mdelay *= backoff

                rv = f(*args, **kwargs)  # Try again
            print str(tries) + " attempts. Abandoning."
            return False  # Ran out of tries

        return f_retry

    return deco_retry