轉載:http://m.survivalescaperooms.com/leleroyn/p/4501359.html
APScheduler是基于Quartz的一個Python定時任務框架,實現了Quartz的所有功能,使用起來十分方便。提供了基于日期、固定時間間隔以及crontab類型的任務,并且可以持久化任務?;谶@些功能,我們可以很方便的實現一個python定時任務系統。
Pip install apscheduler==3.0.3
或者下載源碼,運行命令:
Python setup.py install
#coding=utf-8from apscheduler.schedulers.blocking import BlockingSchedulerfrom datetime import datetimeimport timeimport os def tick(): PRint('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__': scheduler = BlockingScheduler() scheduler.add_job(tick,'cron', second='*/3', hour='*') print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: scheduler.start() except (KeyboardInterrupt, SystemExit): scheduler.shutdown()
新聞熱點
疑難解答