Run a function every X minutes - Python

亡梦爱人 提交于 2019-11-30 08:48:17

Do not use such loop with sleep, it will block gtk from processing any UI events, instead use gtk timer e.g.

def my_timer(*args):
    return True# do ur work here, but not for long

gtk.timeout_add(60*1000, my_timer) # call every min
u0b34a0f6ae

This is exactly like my answer here

If the time is not critical to be exact to the tenth of a second, use

glib.timeout_add_seconds(60, ..)

else as above.

timeout_add_seconds allows the system to align timeouts to other events, in the long run reducing CPU wakeups (especially if the timeout is reocurring) and save energy for the planet(!)

gtk.timeout_add appears to be deprecated, so you should use

def my_timer(*args):
    # Do your work here
    return True

gobject.timeout_add( 60*1000, my_timer )

try:

import wx
wx.CallLater(1000, my_timer)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!