from datetime import date
from apscheduler.scheduler import Scheduler
# Start the scheduler
sched = Scheduler()
sched.start()
# Define the function that is to be executed
def my_job(text):
print text
# The job will be executed on November 6th, 2009
exec_date = date(2009, 11, 6)
# Store the job in a variable in case we want to cancel it
job = sched.add_date_job(my_job, exec_date, ['text'])
你可以使用cron风格的调度来添加一周中某一天的工作。
你的 add_date_job
可以写成 。
sched.add_cron_job(my_job, args = ['text'], day_of_week='tue')
提醒一下,一定要给你的工作添加具体的时间,否则调度器会把默认的时、分、秒作为*,每秒钟都会触发。
apscheduler的参考资料。https:/apscheduler.readthedocs.ioenstableindex.html。