from apscheduler.schedulers.blocking import BlockingScheduler from apscheduler.triggers.cron import CronTrigger from apscheduler.triggers.interval import IntervalTrigger from apscheduler.triggers.date import DateTrigger from apscheduler.triggers.base import BaseTrigger import datetime def aps_test(x): print( datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), x) scheduler = BlockingScheduler() scheduler.add_job(func=aps_test, args=('定时任务',), trigger='cron', hour = 23,minute= 36) scheduler.add_job(func=aps_test, args=('一次性任务',), next_run_time=datetime.datetime.now() + datetime.timedelta(seconds=12)) scheduler.add_job(func=aps_test, args=('循环任务',), trigger='interval', seconds=3) #上面的写法无法pyinstaller到windows #建议写: scheduler.add_job(func=aps_test,args=('定时任务',),trigger=CronTrigger(hour=23,minute=37)) scheduler.add_job(func=aps_test,args=('一次性任务',),trigger=DateTrigger(datetime.datetime.now() + datetime.timedelta(seconds=12))) scheduler.add_job(func=aps_test, args=('循环任务',), trigger=IntervalTrigger(seconds=3)) scheduler.start() #开始任务,上面的任务并行处理