如何在給定時間運行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