do something in time interval

Mathieu Prevot mathieu.prevot at ens.fr
Mon Oct 6 15:25:27 EDT 2008


2008/10/6 Petr Jakeš <petr.jakes at tpc.cz>:
>> 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.
> Petr Jakes

You might want to use threads so you have a very simple code like this:

data data0

thread1:
while True:
  time.sleep(5)
  doSomething(data0)

thread2:
while True:
  time.sleep(0.01)
 doAnotherthing(data0)

thread1 and thread2 can run in parallel; if thread2 take more time,
thread1 won't be impaired.

Mathieu



More information about the Python-list mailing list