日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python apscheduler 阻塞方式只用一个线程_框架APScheduler在python中调度使用的实例详解...

發布時間:2024/10/14 python 66 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python apscheduler 阻塞方式只用一个线程_框架APScheduler在python中调度使用的实例详解... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

最近在研究python調度框架APScheduler使用的路上,那么今天也算個學習筆記吧!# 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秒鐘執行一次

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 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.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 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) #其他任務是獨立的線程執行

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秒執行一次# 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!')

采用阻塞的方法,只執行一次# 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的調度方法# 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!')

總結

以上是生活随笔為你收集整理的python apscheduler 阻塞方式只用一个线程_框架APScheduler在python中调度使用的实例详解...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。