def get(self, block=True, timeout=None): if not self._bucket.can_consume(1): if block: sleep(min(timeout, self._bucket.expected_time()) if timeout else self._bucket.expected_time) else: raise RateLimitExceeded() return super(KTokenBucketGroupQueue, self).get(block=block, timeout=timeout)
def get(self, block=True, timeout=None): tstart = time() get = self._get not_empty = self.not_empty with not_empty: while 1: try: remaining_time, priority_item = get() except Empty: if not block or (timeout and time() - tstart > timeout): raise not_empty.wait(timeout) continue if remaining_time: if not block or (timeout and time() - tstart > timeout): raise Empty() sleep(min(remaining_time, timeout or 1)) else: return priority_item[1]