import time ⏎
from functools import wraps
def throttle(wait):
def decorator(func):
last_call = 0
@wraps(func)
def throttled(*args, **kwargs):
nonlocal last_call
current_time = time.time()
if current_time - last_call >= wait:
last_call = current_time
return func(*args, **kwargs)
return throttled
return decorator