def __call__(self): if self.tokens < self.max_tokens: regen = (timedelta_total_seconds(datetime.now() - self.last_update) / timedelta_total_seconds(self.rate)) self.tokens += regen self.last_update = datetime.now() if self.tokens < 1: if not self.wait: raise RequestException('Requests to %s have exceeded their limit.' % self.domain) wait = timedelta_total_seconds(self.rate) * (1 - self.tokens) log.verbose('Waiting %.2f seconds until next request to %s' % (wait, self.domain)) # Sleep until it is time for the next request time.sleep(wait) self.tokens -= 1
def __call__(self): if self.tokens < self.max_tokens: regen = ( timedelta_total_seconds(datetime.now() - self.last_update) / timedelta_total_seconds(self.rate)) self.tokens += regen self.last_update = datetime.now() if self.tokens < 1: if not self.wait: raise RequestException( 'Requests to %s have exceeded their limit.' % self.domain) wait = timedelta_total_seconds(self.rate) * (1 - self.tokens) log.verbose('Waiting %.2f seconds until next request to %s' % (wait, self.domain)) # Sleep until it is time for the next request time.sleep(wait) self.tokens -= 1
def __call__(self): if self.tokens < self.max_tokens: regen = timedelta_total_seconds(datetime.now() - self.last_update) / timedelta_total_seconds(self.rate) self.tokens += regen self.last_update = datetime.now() if self.tokens < 1: if not self.wait: raise RequestException("Requests to %s have exceeded their limit." % self.domain) wait = timedelta_total_seconds(self.rate) * (1 - self.tokens) # Don't spam console if wait is low if wait < 4: level = log.debug else: level = log.verbose level("Waiting %.2f seconds until next request to %s", wait, self.domain) # Sleep until it is time for the next request time.sleep(wait) self.tokens -= 1
def __call__(self): if self.tokens < self.max_tokens: regen = timedelta_total_seconds( datetime.now() - self.last_update) / timedelta_total_seconds( self.rate) self.tokens += regen self.last_update = datetime.now() if self.tokens < 1: if not self.wait: raise RequestException( 'Requests to %s have exceeded their limit.' % self.domain) wait = timedelta_total_seconds(self.rate) * (1 - self.tokens) # Don't spam console if wait is low if wait < 4: level = log.debug else: level = log.verbose level('Waiting %.2f seconds until next request to %s', wait, self.domain) # Sleep until it is time for the next request time.sleep(wait) self.tokens -= 1