While in Python Timer

4

How to make a timer while? I would like to execute a while, and do something, eg. a

print "hello" 

run "hello" print for 1 hour for example.

    
asked by anonymous 19.06.2016 / 19:29

1 answer

3

You can do this:

import time

end_time = time.time() + 10
countTimer = 0
sleepTime = 0.500
while time.time() < end_time:
    time.sleep(sleepTime)
    countTimer += sleepTime
    print('hello, ja passaram {} secs'.format(countTimer))

Change the 10 by 3600 for a 1 hour. You can remove sleep, but the program will become very heavy

    
19.06.2016 / 19:50