Skip to content

Instantly share code, notes, and snippets.

View johncadengo's full-sized avatar

John Cadengo johncadengo

View GitHub Profile
@johncadengo
johncadengo / throttle.py
Last active September 27, 2022 14:09 — forked from ChrisTM/throttle.py
Python decorator for throttling function calls. Sleeps until it can be called
class throttle(object):
"""Decorator that prevents a function from being called more than once every
time period.
To create a function that cannot be called more than once a minute, but
will sleep until it can be called:
@throttle(minutes=1)
def foo():
pass