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

Y

ycoci0

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
 
K

KenAggie

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
 
D

Dennis Lee Bieber

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
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
D

Diez B. Roggisch

Dennis said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top