David542
David542

Reputation: 110277

Iterating a loop with a pause

I am working to integrate with an API that has a limit on the number of requests per second. Is there a way, when running a for loop in python to delay each cycle? Conceptually, something like --

def function(request):
    for x in [a,b,c,d,...]:
        do something
        wait y seconds

Thank you.

Upvotes: 6

Views: 5610

Answers (1)

Jim Garrison
Jim Garrison

Reputation: 86774

import time
...
time.sleep(5)

This will sleep for 5 seconds. See http://docs.python.org/library/time.html#time.sleep

Upvotes: 9

Related Questions