Skip to content

Unable to get max_delay parameter working #194

@ranjanprasad1996

Description

@ranjanprasad1996

I am trying to achieve the following behaviour with the rate limiter:

  1. The function calls should be rate limited per minute (3/ minute).
  2. The overflowing requests should be in the rate limited bucket only for a maximum of 70 seconds after which it should raise an exception.

I am trying to do this with the max_delay parameter but does not seem to throw any exception after 70 seconds. Not sure if I am missing something.

import time
from multiprocessing.dummy import Pool

from pyrate_limiter import InMemoryBucket
from pyrate_limiter import Limiter, Duration, Rate

limit_s = 3
max_delay_s=70

rates = [Rate(limit_s, Duration.SECOND * 60)]

bucket = InMemoryBucket(rates)

rate_limiter = Limiter(bucket, max_delay=max_delay_s*Duration.SECOND, raise_when_fail=True).as_decorator()


def mapping(*args, **kwargs):
    return "check", 1

@rate_limiter(mapping)
def check_rate_limiter(i):
    print(f"Calling {i} {time.time()}")
    time.sleep(100)
    print(f"Done {i}")


if __name__ == "__main__":
    x = list(range(10))

    with Pool(processes=10) as p:
        p.map(check_rate_limiter, x) 

Also, for any value lower than the limit duration, it throws the
warning Required delay too large: actual=60050, expected=60000 . Any ideas on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions