Connecting Tech Pros Worldwide Forums | Help | Site Map

re : do something in time interval

Hendrik van Rooyen
Guest
 
Posts: n/a
#1: Oct 7 '08
"Petr Jakeš" <petr.jakes@tpc.czwrote:
Quote:
>"Leon Zhang" <safecom@gmail.comwrote:
>
Quote:
>>
>I am not an expert, but why not to use time.sleep(5)?
>If you are using wxPython, you may also try wx.Timer, in which you could
>set its interval.
>>
>>
>Thanks for your reply.
>During the 5s period my script has to do some stuff instead of sleeping.
>Thats why it runs in the loop and once in 5s period it has to trigger some
>other stuff(function, method, action) to do.

import time
while True:
end_time = time.time() + 5
while time.time() < end_time:
do_the_in_between_stuff()
do_the_every_five_second_stuff()

HTH - Hendrik

--
Real programmers disdain structured programming. Structured
programming is for compulsive neurotics who were prematurely
toilet-trained. They wear neckties and carefully line up
pencils on otherwise clear desks.




Lawrence D'Oliveiro
Guest
 
Posts: n/a
#2: Oct 9 '08

re: re : do something in time interval


In message <mailman.2134.1223400793.3487.python-list@python.org>, Hendrik
van Rooyen wrote:
Quote:
import time
while True:
end_time = time.time() + 5
while time.time() < end_time:
do_the_in_between_stuff()
do_the_every_five_second_stuff()
Maybe I'm dense, but ... where do you stop the busy-waiting?
Closed Thread