Identification is rate limited to once every 5 seconds,
so don't try to more often per account, even in different instances.
This method waits for the identification rate limit to be over, then returns.
168799
private void waitForIdentifyRateLimit() {
        String token = api.getPrefixedToken();
        connectionDelaySemaphorePerAccount.computeIfAbsent(token, key -> new Semaphore(1)).acquireUninterruptibly();
        for (long delay = 5100 - (System.currentTimeMillis() - lastIdentificationPerAccount.getOrDefault(token, 0L));
                delay > 0;
                delay = 5100 - (System.currentTimeMillis() - lastIdentificationPerAccount.getOrDefault(token, 0L))) {
            logger.debug("Delaying connecting by {}ms", delay);
            try {
                Thread.sleep(delay);
            } catch (InterruptedException ignored) { }
        }
    }
657884
def rate_limit_ensembl_requests(self):
        
        
        current_time = time.time()
        diff_time = current_time - self.prior_time
        
        # sleep until the current rate limit period is finished
        if diff_time < self.rate_limit:
            time.sleep(self.rate_limit - diff_time)
        
        # set the access time to now, for later checks
        self.prior_time = time.time()
212268
protected function checkLimit()
	{
		$total = 0;
		$context = $this->getContext();
		$config = $context->getConfig();

		/** controller/frontend/customer/limit-count
		 * Maximum number of customers within the time frame
		 *
		 * Creating new customers is limited to avoid abuse and mitigate denial of
		 * service attacks. The number of customer accountss created within the
		 * time frame configured by "controller/frontend/customer/limit-seconds"
		 * are counted before a new customer account (identified by the IP address)
		 * is created. If the number of accounts is higher than the configured value,
		 * an error message will be shown to the user instead of creating a new account.
		 *
		 * @param integer Number of customer accounts allowed within the time frame
		 * @since 2017.07
		 * @category Developer
		 * @see controller/frontend/customer/limit-seconds
		 */
		$count = $config->get( 'controller/frontend/customer/limit-count', 5 );

		/** controller/frontend/customer/limit-seconds
		 * Customer account limitation time frame in seconds
		 *
		 * Creating new customer accounts is limited to avoid abuse and mitigate
		 * denial of service attacks. Within the configured time frame, only a
		 * limited number of customer accounts can be created. All accounts from
		 * the same source (identified by the IP address) within the last X
		 * seconds are counted. If the total value is higher then the number
		 * configured in "controller/frontend/customer/limit-count", an error
		 * message will be shown to the user instead of creating a new account.
		 *
		 * @param integer Number of seconds to check customer accounts within
		 * @since 2017.07
		 * @category Developer
		 * @see controller/frontend/customer/limit-count
		 */
		$seconds = $config->get( 'controller/frontend/customer/limit-seconds', 300 );

		$search = $this->manager->createSearch()->setSlice( 0, 0 );
		$expr = [
			$search->compare( '==', 'customer.editor', $context->getEditor() ),
			$search->compare( '>=', 'customer.ctime', date( 'Y-m-d H:i:s', time() - $seconds ) ),
		];
		$search->setConditions( $search->combine( '&&', $expr ) );

		$this->manager->searchItems( $search, [], $total );

		if( $total > $count ) {
			throw new \Aimeos\Controller\Frontend\Customer\Exception( sprintf( 'Temporary limit reached' ) );
		}
	}
932187
def rate_limit(f):
    
    def new_f(*args, **kwargs):
        errors = 0
        while True:
            resp = f(*args, **kwargs)
            if resp.status_code == 200:
                errors = 0
                return resp
            elif resp.status_code == 401:
                # Hack to retain the original exception, but augment it with
                # additional context for the user to interpret it. In a Python
                # 3 only future we can raise a new exception of the same type
                # with a new message from the old error.
                try:
                    resp.raise_for_status()
                except requests.HTTPError as e:
                    message = "\nThis is a protected or locked account, or" +\
                              " the credentials provided are no longer valid."
                    e.args = (e.args[0] + message,) + e.args[1:]
                    log.warning("401 Authentication required for %s", resp.url)
                    raise
            elif resp.status_code == 429:
                reset = int(resp.headers['x-rate-limit-reset'])
                now = time.time()
                seconds = reset - now + 10
                if seconds < 1:
                    seconds = 10
                log.warning("rate limit exceeded: sleeping %s secs", seconds)
                time.sleep(seconds)
            elif resp.status_code >= 500:
                errors += 1
                if errors > 30:
                    log.warning("too many errors from Twitter, giving up")
                    resp.raise_for_status()
                seconds = 60 * errors
                log.warning("%s from Twitter API, sleeping %s",
                             resp.status_code, seconds)
                time.sleep(seconds)
            else:
                resp.raise_for_status()
    return new_f
809665
def rate_limit(client, headers, atexit=False):
    """"""
    if not client or not headers:
        return False

    if not getattr(client.config, "rate_limit", False):
        return False

    rate_info = RateLimitsInfo.from_headers(headers)
    if not rate_info or not rate_info.interval:
        return False

    if rate_info.interval:
        cb = getattr(client.config, "rate_limit_callback", None)
        if cb and callable(cb):
            cb(rate_info, atexit=atexit)
        time.sleep(rate_info.interval)
    return True
353392
public static nslimitidentifier[] get(nitro_service service, String limitidentifier[]) throws Exception{
		if (limitidentifier !=null && limitidentifier.length>0) {
			nslimitidentifier response[] = new nslimitidentifier[limitidentifier.length];
			nslimitidentifier obj[] = new nslimitidentifier[limitidentifier.length];
			for (int i=0;i<limitidentifier.length;i++) {
				obj[i] = new nslimitidentifier();
				obj[i].set_limitidentifier(limitidentifier[i]);
				response[i] = (nslimitidentifier) obj[i].get_resource(service);
			}
			return response;
		}
		return null;
	}
496549
def _update_callsafety(self, response):
        
        if self.ratelimit is not None:
            self.callsafety['lastcalltime'] = time()
            self.callsafety['lastlimitremaining'] = int(response.headers.get('X-Rate-Limit-Remaining', 0))
742622
private HistoryLimit limitOrNull(int pMaxEntries, long pMaxDuration) {
        return pMaxEntries != 0 || pMaxDuration != 0 ? new HistoryLimit(pMaxEntries, pMaxDuration) : null;
    }
683067
def time_check_allow?(key, stamp)
      Time.now.to_i - stamp.to_i > apply_limit(key)
    end
171122
public static nslimitidentifier_binding get(nitro_service service, String limitidentifier) throws Exception{
		nslimitidentifier_binding obj = new nslimitidentifier_binding();
		obj.set_limitidentifier(limitidentifier);
		nslimitidentifier_binding response = (nslimitidentifier_binding) obj.get_resource(service);
		return response;
	}
645312
private boolean waitForAvailabilityInternal() {
      final Directory directory = indexManager.getDirectoryProvider().getDirectory();
      try {
         Lock lock = directory.obtainLock(IndexWriter.WRITE_LOCK_NAME);
         lock.close();
         return true;
      } catch (LockObtainFailedException lofe) {
         return false;
      } catch (IOException e) {
         log.error(e);
         return false;
      }
   }
818018
def rate_limiting_resettime(self):
        
        if self.__requester.rate_limiting_resettime == 0:
            self.get_rate_limit()
        return self.__requester.rate_limiting_resettime
1278633
private boolean aggregateExistsForCurrentMinute(final MetricIdentity identity) {
		Preconditions.checkNotNull(identity);
		
		if (aggregates.containsKey(identity)) {			
			if (aggregates.get(identity).containsKey(currentMinute)) {
				return true;
			}
		}
		
		return false;
	}
747502
function(id) {
            var itemLimit = this._currentItemLimit,
                fileName;

            if (this._preventRetries[id]) {
                this.log("Retries are forbidden for id " + id, "warn");
                return false;
            }
            else if (this._handler.isValid(id)) {
                fileName = this.getName(id);

                if (this._options.callbacks.onManualRetry(id, fileName) === false) {
                    return false;
                }

                if (itemLimit > 0 && this._netUploadedOrQueued + 1 > itemLimit) {
                    this._itemError("retryFailTooManyItems");
                    return false;
                }

                this.log("Retrying upload for '" + fileName + "' (id: " + id + ")...");
                return true;
            }
            else {
                this.log("'" + id + "' is not a valid file ID", "error");
                return false;
            }
        }
1250929
private boolean checkID(long id) {
    // Ensure that the given ID is a monotonically increasing ID.
    // If the ID is less than the last received ID then reset the
    // last received ID since the connection must have been reset.
    if (lastReceived == 0 || id == lastReceived + 1 || id < lastReceived) {
      lastReceived = id;
      // If the ID reaches the end of the current batch then tell the data
      // source that it's okay to remove all previous messages.
      if (lastReceived % BATCH_SIZE == 0) {
        ack();
      }
      return true;
    } else {
      fail();
    }
    return false;
  }
690445
def _ratelimited_get(self, *args, **kwargs):
        """"""
        with self._ratelimiter:
            resp = self.session.get(*args, **kwargs)

        # It's possible that Space-Track will return HTTP status 500 with a
        # query rate limit violation. This can happen if a script is cancelled
        # before it has finished sleeping to satisfy the rate limit and it is
        # started again.
        #
        # Let's catch this specific instance and retry once if it happens.
        if resp.status_code == 500:
            # Let's only retry if the error page tells us it's a rate limit
            # violation.
            if 'violated your query rate limit' in resp.text:
                # Mimic the RateLimiter callback behaviour.
                until = time.time() + self._ratelimiter.period
                t = threading.Thread(target=self._ratelimit_callback, args=(until,))
                t.daemon = True
                t.start()
                time.sleep(self._ratelimiter.period)

                # Now retry
                with self._ratelimiter:
                    resp = self.session.get(*args, **kwargs)

        return resp
1213070
def maybe_rate_limit(client, headers, atexit=False):
    """"""
    # pylint: disable=fixme
    # pylint: disable=global-statement
    # FIXME: Yes, I know this is not great. We'll fix it later. :-)
    global LAST_CLIENT, LAST_HEADERS

    if LAST_CLIENT and LAST_HEADERS:
        # Wait based on previous client/headers
        rate_limit(LAST_CLIENT, LAST_HEADERS, atexit=atexit)

    LAST_CLIENT = copy.copy(client)
    LAST_HEADERS = copy.copy(headers)