Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pause in "for i in range" with in python

How can I make a pause in a "for i in range" loop, for example after 100 calls?

I have this part of the code:

with open(r'url\url.txt', encoding='utf8') as f:
    for i in range(total_urls):

Now I want to make a big pause after 100 calls.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

All I find is to do time.sleep() or set a random pause between calls, but this is not what I need. I already have a 10 second pause between calls, but I need to make a longer pause after 100 calls.

>Solution :

Like this?

with open(r'url\url.txt', encoding='utf8') as f:
    for i in range(total_urls):
        if i > 0 and i % 100 == 0:
            time.sleep(100)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading