python定时执行任务

  1. from apscheduler.scheduler import Scheduler
  2. import datetime
  3. # Start the scheduler
  4. sched = Scheduler()
  5. def job_function():
  6. print "Hello World" , 'start job1 at: ', datetime.datetime.now()
  7. def job_f():
  8. print "Hello World" , 'start job2 at: ', datetime.datetime.now()
  9. print 'start to sleep'
  10. print 'wake'
  11. print datetime.datetime.now()
  12. sched.daemonic = False
  13. sched.add_cron_job(job_function,day_of_week='5', hour='19', minute='1',second='1')
  14. sched.add_cron_job(job_f,day_of_week='5', hour='20', minute='1',second='1')
  15. sched.start()





原文地址:https://www.cnblogs.com/highroom/p/2ea093ac7e11a8142de9da3f9147c7f2.html