views:

166

answers:

4

has a method in python likw setinterval function in javascript ?

thanks

+2  A: 

The sched module provides these abilities for general Python code. However, as its documentation suggests, if your code is multithreaded it might make more sense to use the threading.Timer class instead.

Eli Bendersky
Good point, forgot about that one! +1
Evgeny
A: 

Things work differently in Python: you need to either sleep() (if you want to block the current thread) or start a new thread. See http://docs.python.org/library/threading.html

Evgeny
Using threads+sleep is not the best way to implement this. Various schedulers and event loops and even convenience stuff in the threading module make better solutions.
Mike Graham
A: 

From Python Documentation:

from threading import Timer

def hello():
    print "hello, world"

t = Timer(30.0, hello)
t.start() # after 30 seconds, "hello, world" will be printed
nailxx
and how to setinterval in python ?
zjm1126
?? Isn't it obvious from example? `Timer(your_interval, your_function_to_call).start()`
nailxx
but setinterval is not settimeout, setinterval is running forever
zjm1126
This *will* run forever. If you want to stop, call `my_timer.stop()`
nailxx
but ,i don't find this ..why ?? it running only once
zjm1126
A: 

Can you explain in more detail what your purpose is?

Depending on what you're doing, a system utility like cron might be what you want.

Mike Graham