def rate_limit(wait_length):
last_time = 0
def decorate(f):
@wraps(f)
def rate_limited(*args, **kwargs):
nonlocal last_time
diff = perf_counter() - last_time
if diff < wait_length:
sleep(wait_length - diff)
r = f(*args, **kwargs)
last_time = perf_counter()
return r
return rate_limited
return decorate
评论列表
文章目录