Go Back   Velocity Reviews > Newsgroups > Python
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

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

 
Thread Tools Search this Thread
Old 06-12-2006, 03:01 AM   #1
Default Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function


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



ycoci0@gmail.com
  Reply With Quote
Old 06-12-2006, 03:50 AM   #2
KenAggie
 
Posts: n/a
Default Re: Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function

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


  Reply With Quote
Old 06-12-2006, 03:57 AM   #3
Dennis Lee Bieber
 
Posts: n/a
Default Re: Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function

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: web-)
HTTP://www.bestiaria.com/
  Reply With Quote
Old 06-12-2006, 07:45 AM   #4
Diez B. Roggisch
 
Posts: n/a
Default 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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump