class RateLimiter(Iterator):
    """Iterator that yields a value at most once every 'interval' seconds."""

def __init__(self, interval):
    self.lock = Lock()
self.interval = interval
self.next_yield = 0

def __next__(self):
    with self.lock:
        pass
Using Python threads to make thousands of calls to a slow API with a rate limit