此代码例如:
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()对象并在该函数中添加它?感谢任何帮助,谢谢!