Python Logo

Python: Throttle utility function

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
Accuracy
100 %
0 Mistakes
CPM
0
Average: 0 CPM
Time
0.000 s
Personal best: -.--- s