Check whether the invocation causes RateExceededError, and update wait time accordingly.
439437
private boolean checkRateExceededErrorAndUpdateWaitTime(
      long clientCustomerId, Throwable throwable) {
    if (ReflectionUtil.isInstanceOf(throwable, "ApiException")) {
      try {
        Object[] errors = (Object[]) ReflectionUtil.invokeNoArgMethod(throwable, "getErrors");
        if (errors == null) {
          return false;
        }
        for (Object error : errors) {
          if (ReflectionUtil.isInstanceOf(error, "RateExceededError")) {
            String rateScope = (String) ReflectionUtil.invokeNoArgMethod(error, "getRateScope");
            Integer retryAfterSeconds =
                (Integer) ReflectionUtil.invokeNoArgMethod(error, "getRetryAfterSeconds");
            logger.info(
                "Encountered RateExceededError: scope={}, seconds={}.",
                rateScope,
                retryAfterSeconds);
            if (retryAfterSeconds == null) {
              logger.warn("Unexpected rate exceeed error, missing retryAfterSeconds");
            } else if (retryAfterSeconds != null) {
              long waitForMillis = getWaitUntilMillis(retryAfterSeconds.intValue());
              if ("DEVELOPER".equals(rateScope)) {
                updateTokenWaitTime(waitForMillis);
                return true;
              } else if ("ACCOUNT".equals(rateScope)) {
                updateAccountWaitTime(clientCustomerId, waitForMillis);
                return true;
              } else {
                logger.warn("Unknown RateExceededError scope: " + rateScope, throwable);
              }
            }
          }
        }
      } catch (RateLimiterReflectionException e) {
        // Failed during reflection analysis, just log and proceed.
        logger.error("Encountered error during analysis using reflection.", e);
      }
    }
    return false;
  }
293433
public void update(final Throwable t) {

		// see if the exception indicates an authorization problem

		boolean isAuthorized = true;

		if (t instanceof HttpException) {
			HttpException httpException = (HttpException) t;

			if (httpException.getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
				isAuthorized = false;
			}
		}

		// adjust the schedule delay based on the type of error

		if (isAuthorized) {

			// Set the last HTTP error (if not already set)

			if (lastHttpError == 0) {
				lastHttpError = System.currentTimeMillis();
			}

			// Set the schedule delay to the elapsed time between now and the start of the HTTP errors
			// Min schedule delay = 1 second
			// Max schedule delay = 1 minute

			long sinceFirstError = System.currentTimeMillis() - lastHttpError;

			scheduleDelay = Math.min(Math.max(sinceFirstError, ONE_SECOND), ONE_MINUTE);

		} else {

			// Set the last HTTP error
			// Set the schedule delay to five minutes

			lastHttpError = System.currentTimeMillis();
			scheduleDelay = FIVE_MINUTES;
		}
	}
543120
def _should_retry(resp):
  """"""
  return (resp.status_code == httplib.REQUEST_TIMEOUT or
          (resp.status_code >= 500 and
           resp.status_code < 600))
348865
def _delay_for_ratelimits(cls, start):
        """"""
        stop = datetime.now()
        duration_microseconds = (stop - start).microseconds
        if duration_microseconds < cls.REQUEST_TIME_MICROSECONDS:
            time.sleep((cls.REQUEST_TIME_MICROSECONDS - duration_microseconds)
                       / MICROSECONDS_PER_SECOND)
123502
def is_error_retryable(request, exc):
    
    if is_last_attempt(request):
        return False

    return (
        isinstance(exc, RetryableException)
        or IRetryableError.providedBy(exc)
    )
1187860
def _rate_limited():
        
        def decorate(func):
            def rate_limited_func(self, *args, **kwargs):
                elapsed = time.monotonic() - self._last_time_called
                self.left_to_wait = self._min_interval - elapsed
                if self.left_to_wait > 0:
                    time.sleep(self.left_to_wait)
                func(self, *args, **kwargs)
                self._last_time_called = time.monotonic()
                yield from func(self, *args, **kwargs)
            return rate_limited_func
        return decorate
1123409
def _wait(self):
		""
		elapsed = time.time() - self.last_called
		must_wait = 1 / self.max_rate - elapsed
		time.sleep(max(0, must_wait))
		self.last_called = time.time()
209763
def _declareTimeoutExceeded(self, ev_data: UpgradeLogData):
        
        logger.info("Timeout exceeded for {}:{}"
                    .format(ev_data.when, ev_data.version))
        last = self._actionLog.last_event
        # TODO test this
        if (last and last.ev_type == UpgradeLog.Events.failed and
                last.data == ev_data):
            return None

        self._action_failed(ev_data, reason="exceeded upgrade timeout")

        self._unscheduleAction()
        self._actionFailedCallback()
479220
def _http_resp_rate_limited(response):
        
        parsed = parse.urlparse(response.request.url)
        duration = int(response.headers.get('Retry-After', 3))
        LOGGER.warning('Rate Limited by %s, retrying in %i seconds',
                       parsed.netloc, duration)
        return asyncio.sleep(duration)
84682
private void checkDone() {
    if (doneHandler != null) {
      if (cause != null) {
        doneHandler.handle(new DefaultFutureResult<T>(cause));
      } else {
        if (count == required) {
          doneHandler.handle(new DefaultFutureResult<T>((T) null));
        }
      }
    }
  }
425866
private void assertInitialized() {

		if (!services.isShuttingDown() && !services.isShutdownDone()) {

			// wait for service layer to be initialized
			while (!services.isInitialized()) {

				try { Thread.sleep(1000); } catch (Throwable t) {}
			}
		}
	}
1170943
def _check_stream_timeout(started, timeout):
    
    if timeout:
        elapsed = datetime.datetime.utcnow() - started
        if elapsed.seconds > timeout:
            raise StopIteration
1256206
public static void checkIfUnmodifiedSince(final String ifUnmodifiedSince, final Instant modified) {
        final Instant time = parseDate(ifUnmodifiedSince);
        if (time != null && modified.truncatedTo(SECONDS).isAfter(time)) {
            throw new ClientErrorException(status(PRECONDITION_FAILED).build());
        }
    }
771200
def rate_limited_old(max_per_second):
    
    lock = threading.Lock()
    min_interval = 1.0 / max_per_second

    def decorate(func):
        last_time_called = time.perf_counter()

        @wraps(func)
        def rate_limited_function(*args, **kwargs):
            lock.acquire()
            nonlocal last_time_called
            try:
                elapsed = time.perf_counter() - last_time_called
                left_to_wait = min_interval - elapsed
                if left_to_wait > 0:
                    time.sleep(left_to_wait)

                return func(*args, **kwargs)
            finally:
                last_time_called = time.perf_counter()
                lock.release()

        return rate_limited_function

    return decorate
1303017
function errorRateLimitExceeded(res) {
  var err = new Error('GitHub rate limit exceeded.');
  err.res = res;
  err.remote = 'github-content-api';
  throw err;
}
147108
private void updateTokenWaitTime(long waitForMillis) {
    final long newTime = millisFromNow(waitForMillis);

    boolean done;
    do {
      long oldTime = tokenWaitUntil.get();
      // If the new wait until time exceeds current one, update it; otherwise just skip the loop.
      if (oldTime < newTime) {
        done = tokenWaitUntil.compareAndSet(oldTime, newTime);
      } else {
        done = true;
      }
    } while (!done);
  }
1190253
def processReqDuringBatch(
            self,
            req: Request,
            cons_time: int):
        
        if self.isMaster:
            self.node.doDynamicValidation(req)
            self.node.applyReq(req, cons_time)