国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

詳解python調(diào)度框架APScheduler使用

2019-11-25 16:17:03
字體:
供稿:網(wǎng)友

最近在研究python調(diào)度框架APScheduler使用的路上,那么今天也算個學(xué)習(xí)筆記吧!

# coding=utf-8"""Demonstrates how to use the background scheduler to schedule a job that executes on 3 secondintervals."""from datetime import datetimeimport timeimport osfrom apscheduler.schedulers.background import BackgroundSchedulerdef tick():  print('Tick! The time is: %s' % datetime.now())if __name__ == '__main__':  scheduler = BackgroundScheduler()  scheduler.add_job(tick, 'interval', seconds=3)  #間隔3秒鐘執(zhí)行一次  scheduler.start()  #這里的調(diào)度任務(wù)是獨(dú)立的一個線程  print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))  try:    # This is here to simulate application activity (which keeps the main thread alive).    while True:      time.sleep(2)  #其他任務(wù)是獨(dú)立的線程執(zhí)行      print('sleep!')  except (KeyboardInterrupt, SystemExit):    # Not strictly necessary if daemonic mode is enabled but should be done if possible    scheduler.shutdown()    print('Exit The Job!')

非阻塞調(diào)度,在指定的時間執(zhí)行一次

# coding=utf-8"""Demonstrates how to use the background scheduler to schedule a job that executes on 3 secondintervals."""from datetime import datetimeimport timeimport osfrom apscheduler.schedulers.background import BackgroundSchedulerdef tick():  print('Tick! The time is: %s' % datetime.now())if __name__ == '__main__':  scheduler = BackgroundScheduler()  #scheduler.add_job(tick, 'interval', seconds=3)  scheduler.add_job(tick, 'date', run_date='2016-02-14 15:01:05')  #在指定的時間,只執(zhí)行一次  scheduler.start()  #這里的調(diào)度任務(wù)是獨(dú)立的一個線程  print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))  try:    # This is here to simulate application activity (which keeps the main thread alive).    while True:      time.sleep(2)  #其他任務(wù)是獨(dú)立的線程執(zhí)行      print('sleep!')  except (KeyboardInterrupt, SystemExit):    # Not strictly necessary if daemonic mode is enabled but should be done if possible    scheduler.shutdown()    print('Exit The Job!')

非阻塞的方式,采用cron的方式執(zhí)行

# coding=utf-8"""Demonstrates how to use the background scheduler to schedule a job that executes on 3 secondintervals."""from datetime import datetimeimport timeimport osfrom apscheduler.schedulers.background import BackgroundSchedulerdef tick():  print('Tick! The time is: %s' % datetime.now())if __name__ == '__main__':  scheduler = BackgroundScheduler()  #scheduler.add_job(tick, 'interval', seconds=3)  #scheduler.add_job(tick, 'date', run_date='2016-02-14 15:01:05')  scheduler.add_job(tick, 'cron', day_of_week='6', second='*/5')  '''    year (int|str) 

主站蜘蛛池模板:
扎鲁特旗|
麻城市|
遂川县|
神农架林区|
钦州市|
永寿县|
农安县|
百色市|
温州市|
永城市|
郑州市|
郁南县|
神农架林区|
开封市|
巴林左旗|
宁海县|
平度市|
吉首市|
唐海县|
泸溪县|
丹棱县|
马公市|
建宁县|
龙山县|
西青区|
昌黎县|
玛纳斯县|
洮南市|
东港市|
奈曼旗|
青铜峡市|
武山县|
盐津县|
凤庆县|
和龙市|
龙川县|
林周县|
镇巴县|
沾益县|
新龙县|
北碚区|