python apscheduler的使用

from apscheduler.schedulers.blocking import BlockingScheduler
from datetime import datetime
def my_job(x=None): print 'hello world'   print x sched = BlockingScheduler() sched.add_job(my_job, 'interval', seconds=5) #每5秒执行一次 sched.start()
############








apscheduler 官网http://pypi.python.org/pypi/APScheduler/2.0.3

from apscheduler.schedulers.blocking import BlockingScheduler
def my_job(x=None):
print x

sched = BlockingScheduler()
sched.add_job(my_job, 'interval', seconds=2, start_date='2017-02-22 17:46:59',args=['123'])#
start_date开始没2秒执行一次

interval 间隔调度

它的参数如下:

weeks(int) – number of weeks to wait

days(int) – number of days to wait

hours(int) – number of hours to wait

minutes(int) – number of minutes to wait

seconds(int) – number of seconds to wait

start_date(datetime|str) – starting point for the interval calculation

end_date(datetime|str) – latest possible date/time to trigger on

更多:http://www.tuicool.com/articles/FbeIRzI

http://www.cnblogs.com/timliucn/p/5894361.html

$ pip install schedule
import schedule
import time

def job():
    print("I'm working...")

schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("10:30").do(job)
schedule.every().monday.do(job)
schedule.every().wednesday.at("13:15").do(job)
# schedule.every(1).seconds.do(job)
while True: schedule.run_pending() time.sleep(1)

https://pypi.python.org/pypi/schedule/官网地址

 

posted @ 2017-02-22 18:10  webbky  阅读(685)  评论(0编辑  收藏  举报