[Tutor] stop a loop after precise amount of time

Saad Javed sbjaved at gmail.com
Sun Nov 25 09:50:16 CET 2012


import time

s = time.time() + 30
running = True
while running:
if time.time() == s:
print 'yes'
running = False

This stops the loop after 30s but the program uses about 12% cpu. What
would be a more efficient way to do this? (p.s. i'm on python 2.7.3)

Saad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121125/79da2e55/attachment-0001.html>


More information about the Tutor mailing list