Python - 我能否将APScheduler作为参数传递?

时间:2017-07-17 18:59:19

标签: python parameter-passing scheduler apscheduler

此代码例如:

def main():

    scheduler = BackgroundScheduler()

    refresh(scheduler)  # refresh will add a job to the scheduler

    while True:
        refresh(scheduler)
        sleep(10)
        continue


def refresh(scheduler):
    rundate = datetime.datetime.now()
    rundate = rundate + datetime.timedelta(seconds=10)
    scheduler.add_job(job_function, run_date=rundate)


def job_function():
    print("Hello, World!")


if __name__ == "__main__":
    main()

运行之后,“Hello,World!”永远不会打印。是否可以传递BackgroundScheduler()对象并在该函数中添加它?感谢任何帮助,谢谢!

0 个答案:

没有答案