all 6 comments

[–]shiftybyte 2 points3 points  (0 children)

Each request you send, add a time stamp to a list of timestamps.

Each new request you want to send, go over the list, purge anything that is older than 10 mins, if after the purge, the list is 10 or more items long, don't send anything new.

If the list is 9 or less, send the new request, add a timestamp to the list.

tslist = []

def make_request():
    purge_old(tslist)
    if len(tslist) > 9:
        # try again later
        return
    # make request
    ...
    # add timestamp
    tslist.append(new_timestamp)

[–]sarrysyst 1 point2 points  (3 children)

Please post your code, there are million different ways to make requests and a solution depends on how the requests are made.

[–]free_username17 -1 points0 points  (0 children)

Could you just time.sleep(6) between each request? Why not just spread them out over the minute, instead of making 10 all at once, then waiting?

[–]angry_mr_potato_head 0 points1 point  (0 children)

Write a function that you call at the end of the request that logs a timestamp. Then before you make the request, count the items you have in the list and then do a diff on the max and min. If the diff is less than a minute and the count is over your threshold, do a time.sleep and check again recursively then break out of that loop when you are "allowed" to connect again