apscheduler.triggers.interval

API

Trigger alias for add_job(): interval

class apscheduler.triggers.interval.IntervalTrigger(weeks=0, days=0, hours=0, minutes=0, seconds=0, start_date=None, end_date=None, timezone=None)

Bases: apscheduler.triggers.base.BaseTrigger

Triggers on specified intervals, starting on start_date if specified, datetime.now() + interval otherwise.

Parameters:
  • weeks (int) – number of weeks to wait
  • days (int) – number of days to wait
  • hours (int) – number of hours to wait
  • minutes (int) – number of minutes to wait
  • seconds (int) – number of seconds to wait
  • start_date (datetime|str) – starting point for the interval calculation
  • end_date (datetime|str) – latest possible date/time to trigger on
  • timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations

Introduction

This method schedules jobs to be run periodically, on selected intervals.

You can also specify the starting date and ending dates for the schedule through the start_date and end_date parameters, respectively. They can be given as a date/datetime object or text (in the ISO 8601 format).

If the start date is in the past, the trigger will not fire many times retroactively but instead calculates the next run time from the current time, based on the past start time.

Examples

from datetime import datetime

from apscheduler.scheduler import BlockingScheduler

def job_function():
print("Hello World") sched = BlockingScheduler() # Schedule job_function to be called every two hours
sched.add_job(job_function, 'interval', hours=2) sched.start()

You can use start_date and end_date to limit the total time in which the schedule runs:

# The same as before, but starts on 2010-10-10 at 9:30 and stops on 2014-06-15 at 11:00
sched.add_job(job_function, 'interval', hours=2, start_date='2010-10-10 09:30', end_date='2014-06-15 11:00)

The scheduled_job() decorator works nicely too:

from apscheduler.scheduler import BlockingScheduler

@sched.scheduled_job('interval', id='my_job_id', hours=2)
def job_function():
print("Hello World")

APScheduler API -- apscheduler.triggers.interval的更多相关文章

  1. APScheduler API -- apscheduler.triggers.date

    apscheduler.triggers.date API Trigger alias for add_job(): date class apscheduler.triggers.date.Date ...

  2. APScheduler API -- apscheduler.triggers.cron

    apscheduler.triggers.cron API Trigger alias for add_job(): cron class apscheduler.triggers.cron.Cron ...

  3. APScheduler API -- apscheduler.schedulers.base

    apscheduler.schedulers.base API class apscheduler.schedulers.base.BaseScheduler(gconfig={}, **option ...

  4. Python 定时任务框架 APScheduler 详解

    APScheduler 最近想写个任务调度程序,于是研究了下 Python 中的任务调度工具,比较有名的是:Celery,RQ,APScheduler. Celery:非常强大的分布式任务调度框架 R ...

  5. python APScheduler模块

    简介 一般来说Celery是python可以执行定时任务, 但是不支持动态添加定时任务 (Django有插件可以动态添加), 而且对于不需要Celery的项目, 就会让项目变得过重. APSchedu ...

  6. apscheduler 绿色版

    由于依赖EntryPoint,因此apscheduler在离线的方式(直接拷贝然后引用)使用时,会报错. 错误信息类似: No trigger by the name “interval/cron/d ...

  7. 用apscheduler处理调度任务,定时任务,重复任务

    from apscheduler.schedulers.blocking import BlockingScheduler from apscheduler.triggers.cron import ...

  8. APScheduler 浅析

    前言 APScheduler是python下的任务调度框架,全程为Advanced Python Scheduler,是一款轻量级的Python任务调度框架.它允许你像Linux下的Crontab那样 ...

  9. python定时任务APScheduler

    APScheduler定时任务 APScheduler 支持三种调度任务:固定时间间隔,固定时间点(日期),Linux 下的 Crontab 命令.同时,它还支持异步执行.后台执行调度任务. 一.基本 ...

随机推荐

  1. Java的Bean

    Bean的定义 遵循Sun的Java Bean规范编写的特殊类 Java Bean的规范 类的访问控制权限是public 类提供有一个无参的构造函数 类的属性的访问控制权限是private,通过set ...

  2. Distinct Substrings SPOJ - DISUBSTR(后缀数组水题)

    求不重复的子串个数 用所有的减去height就好了 推出来的... #include <iostream> #include <cstdio> #include <sst ...

  3. div布局小技巧

    第一: 多个div整齐排列在外层div中,如图: 看到所有小的div的前后左右间隔都相等.假定已经制作好上述单元div控件.在外层大div中循环开始创建它们. for (var i=0; i < ...

  4. Linux下cp ~中关于“~”的疑问

    目的:将wi主文件夹下的.bashrc复制到/tmp,并更名为bashrc.对于书上的代码上加“~”存在疑问. cp ~/.bashrc /tmp/bashrc 对命令进行了以下尝试: 为什么不加“~ ...

  5. ZJOI 2018 一试记

    ZJOI一试几天,天微冷,雨.倒是考试当天近午时分出了太阳. 开题前的一刻,心情反而平静了,窗外泛着淡金色的日光照进来,仿佛今天的我并不是所谓来冲击省队,而只是来经历一场洗礼. 开题了,虽然有一点小插 ...

  6. 20165218 《网络对抗技术》Exp0 Kali安装 Week1

    Kali Linux安装 下载 在Kali官网下载Kali Linux 64 Bit版本 打开VM,选择文件->新建虚拟机,一直点击下一步,注意这里选择稍后安装操作系统 版本中找不到Kali,可 ...

  7. AS可视化布局中文乱码

    求助android studio 的可视化布局中文乱码-CSDN论坛-CSDN.NET-中国最大的IT技术社区http://bbs.csdn.net/topics/391887442 Android ...

  8. [学习笔记]平衡树(Splay)——旋转的灵魂舞蹈家

    1.简介 首先要知道什么是二叉查找树. 这是一棵二叉树,每个节点最多有一个左儿子,一个右儿子. 它能支持查找功能. 具体来说,每个儿子有一个权值,保证一个节点的左儿子权值小于这个节点,右儿子权值大于这 ...

  9. JavaWeb中的多数据源开发

    从我们接触Javaweb开始,ssh框架或者ssm等或许是惊叹于框架的强大之处还是自身的迷茫,一直没有注意到一个问题就是:在我的项目中在spring中所配置的数据源都是指向单一数据库,都是单数据源,一 ...

  10. 二分查找(等于x,小于x,小于等于x,大于x,大于等于x )

    //等于x//小于x//小于等于x//大于x//大于等于x #include <cstdio> #include <cstdlib> #include <cmath> ...