Skip to content

Instantly share code, notes, and snippets.

@laixintao
Created January 21, 2020 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laixintao/1aa72167c65e1ba28767e2cad21da0cc to your computer and use it in GitHub Desktop.
Save laixintao/1aa72167c65e1ba28767e2cad21da0cc to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from ratelimit import limits, sleep_and_retry
from time import time
count = 0
@sleep_and_retry
@limits(calls=3, period=5)
def call_api():
print(f"called! on {time()=} {count=}")
while 1:
call_api()
@laixintao
Copy link
Author

called! on time()=1579574892.050764 count=0
called! on time()=1579574892.051442 count=0
called! on time()=1579574892.051451 count=0
called! on time()=1579574897.052951 count=0
called! on time()=1579574897.053015 count=0
called! on time()=1579574897.0530372 count=0
called! on time()=1579574902.0550752 count=0
called! on time()=1579574902.0551832 count=0
called! on time()=1579574902.055276 count=0
called! on time()=1579574907.060375 count=0
called! on time()=1579574907.0604742 count=0
called! on time()=1579574907.0605571 count=0
called! on time()=1579574912.0645068 count=0
called! on time()=1579574912.064673 count=0
called! on time()=1579574912.0647218 count=0
called! on time()=1579574917.067601 count=0
called! on time()=1579574917.067698 count=0
called! on time()=1579574917.067741 count=0

https://github.com/tomasbasham/ratelimit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment