Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function

Discussion in 'Python' started by ycoci0@gmail.com, Jun 12, 2006.

  1. Guest

    Hi all,

    Not exactly new to Python, just have not programmed a time dependent
    function using it before.

    I imagine that many of you may also program some JavaScript and may be
    familiar with JavaScript's SetTimeout( expression, after time interval
    in milliseconds) function. Does Python have an equivalent to this?

    A SetTimeout-like Python function would be ideal for my application.


    Best,

    Y-coci
    , Jun 12, 2006
    #1
    1. Advertising

  2. KenAggie Guest

    Yea -- the "sched" class is exactly what you need. Just import sched
    and then use it to schedule a function call in the future, either using
    relative time or an absolute time. The python help file tells you how
    in detail.
    - Ken

    wrote:
    > Hi all,
    >
    > Not exactly new to Python, just have not programmed a time dependent
    > function using it before.
    >
    > I imagine that many of you may also program some JavaScript and may be
    > familiar with JavaScript's SetTimeout( expression, after time interval
    > in milliseconds) function. Does Python have an equivalent to this?
    >
    > A SetTimeout-like Python function would be ideal for my application.
    >
    >
    > Best,
    >
    > Y-coci
    KenAggie, Jun 12, 2006
    #2
    1. Advertising

  3. On 11 Jun 2006 20:01:28 -0700, declaimed the following
    in comp.lang.python:

    > I imagine that many of you may also program some JavaScript and may be
    > familiar with JavaScript's SetTimeout( expression, after time interval
    > in milliseconds) function. Does Python have an equivalent to this?
    >

    I don't know? How does "SetTimeout" actually behave? Asynchronously?
    Synchronously? That is... would

    import time

    print "I'm tired"
    time.sleep(60)
    print "Ah, a short nap"

    be the type of behavior you are wanting?

    Or do you mean you want to do other stuff while the timer is
    running, then have the program interrupted to run the timed function,
    and then return to the main program?
    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
    Dennis Lee Bieber, Jun 12, 2006
    #3
  4. Re: Evaluating a Function After X Seconds: Python Equivalent to JavaScript'sSetTimeout() Function

    Dennis Lee Bieber schrieb:
    > I don't know? How does "SetTimeout" actually behave? Asynchronously?
    > Synchronously? That is... would


    The former. It is the poor-mans threading of JavaScript so to speak.

    Diez
    Diez B. Roggisch, Jun 12, 2006
    #4
    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. tshad
    Replies:
    7
    Views:
    16,880
    tshad
    Mar 11, 2005
  2. 00_CP_D12
    Replies:
    3
    Views:
    8,865
    dilipv
    Feb 22, 2008
  3. Stu
    Replies:
    7
    Views:
    1,720
    Dave Thompson
    Mar 7, 2005
  4. Michael Tan
    Replies:
    32
    Views:
    910
    Ara.T.Howard
    Jul 21, 2005
  5. `p
    Replies:
    7
    Views:
    349
    Steve Litt
    Dec 14, 2005
Loading...

Share This Page