I'm using gobject.timeout_add() to display a timer in my project (dojotools).
I was wondering if there is 开发者_如何学运维any other way to achieve the same results, but without the gobject dependency.
The requirement is just calling a method repeatedly, in a certain time interval.
You can use a thread with time.sleep(interval) to achieve the same effect.
import thread, time
def timer():
while True:
time.sleep(1)
# do something here
thread.start_new_thread(timer, ())
If you are OK with using TkInter, which should be available on all Pythons (except cell phones and maybe some tablets), you can use TkInter's after()
function.
That would avoid the blocking that sleep causes.
精彩评论