最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用APScheduler3.0.1 實(shí)現(xiàn)定時(shí)任務(wù)的方法

 更新時(shí)間:2019年07月22日 08:54:30   作者:小橘子Pythoner  
今天小編就為大家分享一篇使用APScheduler3.0.1 實(shí)現(xiàn)定時(shí)任務(wù)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

需求是在某一指定的時(shí)刻執(zhí)行操作

網(wǎng)上的建議多為通過調(diào)用Scheduler的add_date_job實(shí)現(xiàn)

不過APScheduler 3.0.1與之前差異較大, 無法通過上述方法實(shí)現(xiàn)

參考 https://apscheduler.readthedocs.org/en/latest/userguide.html APScheduler 3.0.1的userguide 解決問題

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.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)
 except (KeyboardInterrupt, SystemExit):
  scheduler.shutdown() # Not strictly necessary if daemonic mode is enabled but should be done if possible

實(shí)例的代碼實(shí)現(xiàn)每3秒執(zhí)行一次tick方法,雖然與需求不符,但發(fā)現(xiàn)add_interval_job在APScheduler 3.0.1中 已經(jīng)被

scheduler.add_job(tick, 'interval', seconds=3)

取代。

help(scheduler.add_job)得到

add_job(func, trigger=None, args=None, kwargs=None, id=None, name=None, misfire_grace_time=undefined, coalesce=undefined, max_instances=undefined, next_run_time=undefined, jobstore='default', executor='default', replace_existing=False, **trigger_args)
Adds the given job to the job list and wakes up the scheduler if it's already running.
 
Any option that defaults to undefined will be replaced with the corresponding default value when the job is scheduled (which happens when the scheduler is started, or immediately if the scheduler is already running).
 
The func argument can be given either as a callable object or a textual reference in the package.module:some.object format, where the first half (separated by :) is an importable module and the second half is a reference to the callable object, relative to the module.
 
The trigger argument can either be:
the alias name of the trigger (e.g. date, interval or cron), in which case any extra keyword arguments to this method are passed on to the trigger's constructor
an instance of a trigger class

由此可知,第參數(shù)為trigger,可取值為 date、interval、cron, **trigger_args為該trigger的構(gòu)造函數(shù)。

通過源碼找到DateTrigger 的構(gòu)造函數(shù)

def __init__(self, run_date=None, timezone=None)

所以,只需將指定的時(shí)間傳入add_job

scheduler.add_job(tick, 'date', run_date='2014-11-11 14:48:00')

以上這篇使用APScheduler3.0.1 實(shí)現(xiàn)定時(shí)任務(wù)的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • python?Opencv實(shí)現(xiàn)停車位識(shí)別思路詳解

    python?Opencv實(shí)現(xiàn)停車位識(shí)別思路詳解

    這篇文章主要介紹了Opencv實(shí)現(xiàn)停車位識(shí)別,本文通過示例代碼場(chǎng)景分析給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • 利用Python操作消息隊(duì)列RabbitMQ的方法教程

    利用Python操作消息隊(duì)列RabbitMQ的方法教程

    RabbitMQ是一個(gè)在AMQP基礎(chǔ)上完整的,可復(fù)用的企業(yè)消息系統(tǒng)。他遵循Mozilla Public License開源協(xié)議。下面這篇文章主要給大家介紹了關(guān)于利用Python操作消息隊(duì)列RabbitMQ的方法教程,需要的朋友可以參考下。
    2017-07-07
  • Python中實(shí)現(xiàn)常量(Const)功能

    Python中實(shí)現(xiàn)常量(Const)功能

    這篇文章主要介紹了Python中實(shí)現(xiàn)常量(Const)功能,python語(yǔ)言本身沒有提供const,本文使用一個(gè)類來實(shí)現(xiàn)常量定義功能,并介紹了使用方法,需要的朋友可以參考下
    2015-01-01
  • Pycharm打印大數(shù)據(jù)文件顯示不全的解決方法

    Pycharm打印大數(shù)據(jù)文件顯示不全的解決方法

    這篇文章主要介紹了Pycharm打印大數(shù)據(jù)文件顯示不全的解決方法,昨晚寫了個(gè)小爬蟲,簡(jiǎn)單分析下發(fā)現(xiàn)可以修改請(qǐng)求的url,直接獲取所有目標(biāo)的數(shù)據(jù),想先打印在控制臺(tái)看看,發(fā)現(xiàn)打印的數(shù)據(jù)不全,所以本文記錄了一下解決方法,需要的朋友可以參考下
    2024-03-03
  • python requests庫(kù)的使用

    python requests庫(kù)的使用

    這篇文章主要介紹了python requests庫(kù)的使用,幫助大家更好的利用python進(jìn)行爬蟲,感興趣的朋友可以了解下
    2021-01-01
  • python中_init_.py的作用

    python中_init_.py的作用

    __init__.py的作用是告訴Python這是一個(gè)包,并且可以包含初始化操作、控制子模塊導(dǎo)入、設(shè)置包級(jí)別變量和函數(shù)等,本文就來詳細(xì)的介紹一下_init_.py的作用,感興趣的可以了解一下
    2025-01-01
  • python 指定源路徑來解決import問題的操作

    python 指定源路徑來解決import問題的操作

    這篇文章主要介紹了python 指定源路徑來解決import問題的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • 用Python的urllib庫(kù)提交WEB表單

    用Python的urllib庫(kù)提交WEB表單

    上次實(shí)現(xiàn)的校園網(wǎng)IP網(wǎng)關(guān)登錄器其中一個(gè)關(guān)鍵部分就是提交登錄網(wǎng)頁(yè)的表單,下面是我的Python實(shí)現(xiàn)代碼
    2009-02-02
  • 基于python元祖與字典與集合的粗淺認(rèn)識(shí)

    基于python元祖與字典與集合的粗淺認(rèn)識(shí)

    下面小編就為大家?guī)硪黄趐ython元祖與字典與集合的粗淺認(rèn)識(shí)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08
  • Python的類成員變量默認(rèn)初始值的坑及解決

    Python的類成員變量默認(rèn)初始值的坑及解決

    這篇文章主要介紹了Python的類成員變量默認(rèn)初始值的坑及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02

最新評(píng)論

石狮市| 晋中市| 西城区| 当涂县| 邳州市| 介休市| 宁强县| 腾冲县| 鄢陵县| 乌拉特前旗| 昂仁县| 喀喇沁旗| 孟连| 九龙城区| 互助| 陇南市| 宜宾县| 德昌县| 宜兰市| 东台市| 奉化市| 镇原县| 太仆寺旗| 雅江县| 彝良县| 井研县| 施甸县| 若羌县| 汤原县| 灵璧县| 天镇县| 中卫市| 台南县| 西充县| 南澳县| 阿拉善右旗| 泾川县| 章丘市| 怀安县| 自贡市| 望奎县|