re : do something in time interval

Discussion in 'Python' started by Hendrik van Rooyen, Oct 8, 2008.

  1. "Petr Jakeš" <> wrote:

    >"Leon Zhang" <> wrote:
    >
    >>
    >> 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.
     
    Hendrik van Rooyen, Oct 8, 2008
    #1
    1. Advertising

  2. In message <>, Hendrik
    van Rooyen wrote:

    > 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?
     
    Lawrence D'Oliveiro, Oct 9, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dica
    Replies:
    0
    Views:
    418
  2. Wes Harrison

    Measuring a short interval in time

    Wes Harrison, Sep 14, 2004, in forum: Java
    Replies:
    2
    Views:
    618
    Paul Lutus
    Sep 14, 2004
  3. Graeme Longman
    Replies:
    1
    Views:
    323
    Waldemar Osuch
    Aug 4, 2004
  4. Petr Jakes

    do something in time interval

    Petr Jakes, Oct 6, 2008, in forum: Python
    Replies:
    4
    Views:
    391
    Mathieu Prevot
    Oct 6, 2008
  5. Andrew Poulos

    'point in time' time interval

    Andrew Poulos, Jun 14, 2005, in forum: Javascript
    Replies:
    4
    Views:
    296
    Andrew Poulos
    Jun 15, 2005
Loading...

Share This Page