Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function (http://www.velocityreviews.com/forums/t358571-evaluating-a-function-after-x-seconds-python-equivalent-to-javascripts-settimeout-function.html)

ycoci0@gmail.com 06-12-2006 03:01 AM

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


KenAggie 06-12-2006 03:50 AM

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

ycoci0@gmail.com 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



Dennis Lee Bieber 06-12-2006 03:57 AM

Re: Evaluating a Function After X Seconds: Python Equivalent to JavaScript's SetTimeout() Function
 
On 11 Jun 2006 20:01:28 -0700, ycoci0@gmail.com 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
wlfraed@ix.netcom.com wulfraed@bestiaria.com
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-asst@bestiaria.com)
HTTP://www.bestiaria.com/

Diez B. Roggisch 06-12-2006 07:45 AM

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


All times are GMT. The time now is 10:06 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.