如何在给定时间运行Python中的函数?Python - 在给定时间启动函数
例如:
run_it_at(func, '2012-07-17 15:50:00')
,它会在2012-07-17 15:50:00运行功能func
。
我试过sched.scheduler,但它没有启动我的功能。
import time as time_module
scheduler = sched.scheduler(time_module.time, time_module.sleep)
t = time_module.strptime('2012-07-17 15:50:00', '%Y-%m-%d %H:%M:%S')
t = time_module.mktime(t)
scheduler_e = scheduler.enterabs(t, 1, self.update,())
我该怎么办?
什么操作系统?您可能需要使用python外部的程序运行它,例如unix上的cron。 – 2012-07-17 13:51:31
为什么不呢?你为“进入”设定了什么延迟(假设你尝试过)? – 2012-07-17 13:51:57
你是如何尝试使用'sched.scheduler'的? – geoffspear 2012-07-17 13:52:52