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