国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - 詳解python調度框架APScheduler使用

詳解python調度框架APScheduler使用

2020-09-27 10:41帥胡 Python

本篇文章主要介紹了詳解python調度框架APScheduler使用,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
"""
 
from datetime import datetime
import time
import os
 
from apscheduler.schedulers.background import BackgroundScheduler
 
 
def 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()  #這里的調度任務是獨立的一個線程
  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#其他任務是獨立的線程執(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!')

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
"""
 
from datetime import datetime
import time
import os
 
from apscheduler.schedulers.background import BackgroundScheduler
 
 
def 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()  #這里的調度任務是獨立的一個線程
  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#其他任務是獨立的線程執(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í)行

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
"""
 
from datetime import datetime
import time
import os
 
from apscheduler.schedulers.background import BackgroundScheduler
 
 
def 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#其他任務是獨立的線程執(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!')

阻塞的方式,間隔3秒執(zhí)行一次

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
"""
 
from datetime import datetime
import os
 
from apscheduler.schedulers.blocking import BlockingScheduler
 
 
def tick():
  print('Tick! The time is: %s' % datetime.now())
 
 
if __name__ == '__main__':
  scheduler = BlockingScheduler()
  scheduler.add_job(tick, 'interval', seconds=3)
  
  print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
 
  try:
    scheduler.start()  #采用的是阻塞的方式,只有一個線程專職做調度的任務
  except (KeyboardInterrupt, SystemExit):
    # Not strictly necessary if daemonic mode is enabled but should be done if possible
    scheduler.shutdown()
    print('Exit The Job!')

采用阻塞的方法,只執(zhí)行一次

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
"""
 
from datetime import datetime
import os
 
from apscheduler.schedulers.blocking import BlockingScheduler
 
 
def tick():
  print('Tick! The time is: %s' % datetime.now())
 
 
if __name__ == '__main__':
  scheduler = BlockingScheduler()
  scheduler.add_job(tick, 'date', run_date='2016-02-14 15:23:05')
  
  print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
 
  try:
    scheduler.start()  #采用的是阻塞的方式,只有一個線程專職做調度的任務
  except (KeyboardInterrupt, SystemExit):
    # Not strictly necessary if daemonic mode is enabled but should be done if possible
    scheduler.shutdown()
    print('Exit The Job!')

采用阻塞的方式,使用cron的調度方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# coding=utf-8
"""
Demonstrates how to use the background scheduler to schedule a job that executes on 3 second
intervals.
"""
 
from datetime import datetime
import os
 
from apscheduler.schedulers.blocking import BlockingScheduler
 
 
def tick():
  print('Tick! The time is: %s' % datetime.now())
 
 
if __name__ == '__main__':
  scheduler = BlockingScheduler()
  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
  '''
  
  print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
 
  try:
    scheduler.start()  #采用的是阻塞的方式,只有一個線程專職做調度的任務
  except (KeyboardInterrupt, SystemExit):
    # Not strictly necessary if daemonic mode is enabled but should be done if possible
    scheduler.shutdown()
    print('Exit The Job!')

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:http://www.cnblogs.com/hushaojun/p/5189109.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美日本韩国一区二区 | 久热久热 | 久久精品成人 | 精品日韩一区二区 | 毛片xxx| 激情一区二区三区 | 国产精品国产精品国产专区不卡 | 羞羞视频免费观看 | 中文字幕免费中文 | 日韩一区在线视频 | 福利资源在线观看 | 久久在线视频 | h视频免费观看 | 免费在线观看一区二区 | 久久精品麻豆 | 亚洲一区中文字幕 | 日韩精品视频在线播放 | 精品黑人一区二区三区久久 | 久久福利 | 久久久久国产精品午夜一区 | 国产一区二区视频精品 | 久久亚洲国产精品 | 久久爱成人 | a久久久 | 在线国产视频观看 | 国产一区二区三区久久 | 91久久久久久久久久久久久 | 日本久久网 | 欧美成人精品在线视频 | 欧美日韩精品电影 | 亚洲视频 欧美视频 | 成人特黄a级毛片免费视频 国产在线视频一区二区 | 欧美在线观看免费观看视频 | 日本在线观看一区二区 | 亚洲在线一区二区 | 日韩欧美一区二区三区 | 日韩亚洲一区二区 | 国产精品久久久久久久久久三级 | 天天干人人 | 欧美日韩综合精品 | 日韩和的一区二在线 |