APScheduler four module components:
Triggers triggers: trigger conditions are set for the task
Task store job
stores: used to store the task, the task is stored in memory or database
Actuator executors: to perform a task, you can set execution mode is single-threaded or thread pool
The scheduler schedulers: parameters as the above three components, the scheduler operates by creating instances
Detailed scheduler component
Development needs to select the appropriate components according to the following different scheduler component:
BlockingScheduler
Blocking Scheduler: program only applies to run scheduler.
BackgroundScheduler
Background Scheduler: For the case of non-blocking, the scheduler will run independently in the background.
AsyncIOScheduler
AsyncIO scheduler for application in the case of using AsnycIO.
GeventScheduler
Gevent scheduler for the case by use of Gevent.
TornadoScheduler
Tornado scheduler for Tornado build applications.
TwistedScheduler
Twisted scheduler for Twisted build applications.
QtScheduler
Scheduler Qt, Qt use in building applications.
Configuring a task,
Set up a task trigger. Triggers can be set to run periodic tasks, frequency and duration. APScheduler There are three built-in triggers:
date Date: trigger specific date for a task to run
interval interval: time-triggered task run interval
cron Period: Period triggered task to run
from apscheduler.schedulers.blocking import BlockingScheduler import datetime,os,threading def func(): print('%s,%s,%s,%s'%((datetime.datetime.now()),'hello',os.getppid(),os.getpid())) if __name__ =='__main__': apsched = BlockingScheduler() apsched.add_job (FUNC, ' interval The ' , =. 5 seconds The) # interval scheduling interval The apsched.start ()
Scheduling interval corresponding value
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
from apscheduler.schedulers.blocking import BlockingScheduler import datetime,os,threading def func(): print('%s,%s,%s,%s'%((datetime.datetime.now()),'hello',os.getppid(),os.getpid())) if __name__ =='__main__': apsched = BlockingScheduler() apsched.add_job (FUNC, ' the cron ' , DAY_OF_WEEK = ' Mon-Fri ' , minute = ' * ' , SECOND = ' * /. 3 ' ) # timing of scheduling the cron apsched.start ()
Scheduling Timing
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)