Python 定时调度机制 – APScheduler Job的参数传递

关键词:APScheduler; Python; 定时机制;调度机制;Job传递参数

APScheduler调度模块使用详解可参考:
官方文档:userguide
博客

使用APScheduler机制时,向job传递参数的代码示例:

from apscheduler.schedulers.blocking import BlockingScheduler
  
def job1(para1, para2,para3):
    print("This is job1")
    print("The para1 is "+str(para1))
    print("The para2 is "+str(para2))
    print("The para2 is "+str(para2))
def job2(para1, para2,para3):
    print("This is job2")
    print("The para1 is "+str(para1))
    print("The para2 is "+str(para2))
    print("The para2 is "+str(para2))

scheduler.add_job(job1, 'interval', seconds=20,args=['para1','para2','para3'])
scheduler.add_job(job2, 'interval', seconds=20,kwargs={'para1':'3','para2':'2','para3':'1'})
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))

try:
    scheduler.start()
except (KeyboardInterrupt, SystemExit):
    scheduler.shutdown(wait=False)

你可能感兴趣的:(Python 定时调度机制 – APScheduler Job的参数传递)