In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to realize the APScheduler timing task of the python package". The editor shows you the operation process through the actual case, the operation method is simple and fast, and the practicality is strong. I hope this article "how to realize the APScheduler timing task of the python package" can help you solve the problem.
1. Install pip install apscheduler 2. Execute it regularly.
Create a new scheduler scheduler
Add a job store scheduling task
Run scheduling task
Import datetimefrom apscheduler.schedulers.blocking import BlockingSchedulerdef task (name): print (% s tells you the time is:% s. Format (name, datetime.datetime.now ()) # the task will be executed once at 13:14:52 on 2022-05-20 scheduler = BlockingScheduler () scheduler.add_job (task, 'date', run_date=datetime.datetime (2022, 5, 20, 13, 14, 52), args= [' autofelix'], id='task') scheduler.start () III.
When you schedule a job, you need to select a trigger for the job to describe when the job is triggered
Date specifies a date at one time
How often does interval execute within a certain time range?
From apscheduler.schedulers.blocking import BlockingSchedulerdef task (): print ('I am Brother Flying Rabbit') # execute scheduler = BlockingScheduler () scheduler.add_job (task, 'interval', seconds=10, id='task') scheduler.start () every 10 seconds.
Cron and Linux crontab formats are compatible and the most powerful
From apscheduler.schedulers.blocking import BlockingSchedulerf = open ('status.text',' asides, encoding='utf8') sc = BlockingScheduler () @ sc.scheduled_job ('cron', day_of_week='*', hour=1, minute='30') Second='50') if name ='_ _ main__':try:sc.start () f.write ('scheduled task successfully executed') except Exception as e:sc.shutdown () f.write ('scheduled task execution failed') finally:f.close () 5. Execute every few minutes
/ 2: executed every 2 minutes
/ 1: executed every 1 minute
From apscheduler.schedulers.blocking import BlockingSchedulerdef task (): print ('your task is executed every 2 minutes') scheduler = BlockingScheduler () scheduler.add_job (job1, 'cron', minute= "/ 2", id='task') scheduler.start () 6. Execute every hour
Jitter: represents the number of seconds that can float up and down
From apscheduler.schedulers.blocking import BlockingSchedulerdef task (): print ('your task is executed every hour') scheduler = BlockingScheduler () scheduler.add_job (task, 'interval', hours=1, id='task') # scheduler.add_job (task,' interval', hours=1, id='task', jitter=120) scheduler.start () 7. Scheduler category
BlockingScheduler: when the scheduler is the only thing to run in your application
BackgroundScheduler: use it when you are not running any other framework and want the scheduler to execute in the background of your application (even if the charging pile is in this way)
AsyncIOScheduler: use it when your program uses asyncio (an asynchronous framework)
GeventScheduler: use it when your program uses gevent (the high-performance Python concurrency framework)
TornadoScheduler: use it when your program is based on Tornado (a web framework)
TwistedScheduler: use it when your program uses Twisted (an asynchronous framework)
QtScheduler: if your application is a Qt application, you can use it
This is the end of the content about "how to implement the APScheduler timing task of the python package". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.