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

首頁 > 編程 > Python > 正文

詳解python調度框架APScheduler使用

2020-02-23 04:30:46
字體:
來源:轉載
供稿:網友

最近在研究python調度框架APScheduler使用的路上,那么今天也算個學習筆記吧!

# 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秒鐘執行一次  scheduler.start()  #這里的調度任務是獨立的一個線程  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)  #其他任務是獨立的線程執行      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!')

非阻塞調度,在指定的時間執行一次

# 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.start()  #這里的調度任務是獨立的一個線程  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)  #其他任務是獨立的線程執行      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的方式執行

# 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) – 4-digit year    month (int|str) – month (1-12)    day (int|str) – day of the (1-31)    week (int|str) – ISO week (1-53)    day_of_week (int|str) – number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun)    hour (int|str) – hour (0-23)    minute (int|str) – minute (0-59)    second (int|str) – second (0-59)        start_date (datetime|str) – earliest possible date/time to trigger on (inclusive)    end_date (datetime|str) – latest possible date/time to trigger on (inclusive)    timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations (defaults to scheduler timezone)      *  any  Fire on every value    */a  any  Fire every a values, starting from the minimum    a-b  any  Fire on any value within the a-b range (a must be smaller than b)    a-b/c  any  Fire every c values within the a-b range    xth y  day  Fire on the x -th occurrence of weekday y within the month    last x  day  Fire on the last occurrence of weekday x within the month    last  day  Fire on the last day within the month    x,y,z  any  Fire on any matching expression; can combine any number of any of the above expressions  '''  scheduler.start()  #這里的調度任務是獨立的一個線程  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)  #其他任務是獨立的線程執行      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!')            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黔江区| 荥阳市| 筠连县| 永州市| 清水县| 吕梁市| 尚志市| 晋宁县| 德格县| 沁阳市| 德阳市| 临潭县| 大姚县| 高台县| 南开区| 灵丘县| 湖南省| 浏阳市| 盱眙县| 临汾市| 福海县| 通城县| 驻马店市| 贵溪市| 台北县| 蒙阴县| 聂拉木县| 多伦县| 乌拉特中旗| 澄城县| 包头市| 南川市| 宣恩县| 凤凰县| 长乐市| 嵊泗县| 紫金县| 威信县| 容城县| 孟连| 鄂托克前旗|