Python timed task Framework Apscheduler 3.0.3 Cron Example

Source: Internet
Author: User

Apscheduler is a Python timed task framework based on Quartz, which realizes all the functions of quartz and is very convenient to use. Provides tasks based on date, fixed time interval, and crontab type, and can be persisted. Based on these features, we can easily implement a Python timed task system .

Installation

The installation process is simple and can be based on PIP and source code.

Pip Install apscheduler==3.0.3

or download the source code, run the command:

Python setup.py Install

Cron Job Example
   1:  #coding =utf-8
   2:  from apscheduler.schedulers.blocking import Blockingscheduler
   3:  from datetime import datetime
   4:  Import Time
   5:  import os
   6:     
   7:  def tick ():
   8:      print (' tick! The time is:%s ' % DateTime.Now ())
   9:  
  :  if' __main__ ':
One   :      Scheduler = Blockingscheduler ()
  :      scheduler.add_job (tick,' cron ', second=' */3 ', hour=' * ') )    
  :      print (' press ctrl+{0} to exit '. Format (' break 'if ' NT ' Else ' C '))
  :      try:
  :          Scheduler.start ()
  :      except (Keyboardinterrupt, Systemexit):
  17:          
  :  
  :  
  :  
Cron expressionType description

Expression

Field

Description

*

Any

Fire on every value

*/a

Any

Fire every a values, starting from the minimum

A-B

Any

Fire in any value within the-a-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

Any

Fire on any matching expression; Can combine any number of any of the above expressions

Python timed task Framework Apscheduler 3.0.3 Cron Example

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.