S
S
Sergey Karbivnichy2015-11-23 15:45:28
Python
Sergey Karbivnichy, 2015-11-23 15:45:28

How to pause the loop every 20 seconds for 2 seconds?

There is a cycle. You need to stop it every 20 seconds for 2 seconds. How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nirvimel, 2015-11-23
@hottabxp

import time

repeat_interval = 5
waiting_interval = 2

destination = time.time() + repeat_interval
for x in xrange(100000000):
    # Your code here
    time.sleep(0.001)
    now = time.time()
    if now > destination:
        destination += repeat_interval
        print('Go sleeping')
        time.sleep(waiting_interval)
        print('Waking up')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question