Q:

Limit loop to N iterations per minute

Could someone please give me some help with limiting a loop to N iterations per minute in Python.
Lets say I have
limit = 5
for items in recvData:
     # > limit iterations in past minute? -> sleep for 60 seconds from last iterations before proceeding? #
     ... do work ...

How would I do the time check / sleeping to give the correct flow. I'm not worried about blocking the executing thread/process while it waits.
Thanks

A:

It should be noted that this is not "hard real time" code. this will be off slightly because of OS scheduling and the like. That being said, unless you know that you need hard real time, this should suffice.    
import time

limit = 5
starttime = time.time()
for i, item in enumerate(recvData):
    if not i + 1 % limit:
        sleeptime =starttime + 60 - time.time()
        if sleeptime > 0:
            time.sleep(sleeptime)
        starttime = time.time()
    #processing code

