我有python代码,我正在为一个网站开发,其中包括创建excel表,然后将其转换为json文件。我需要这个代码持续运行,除非它被网站管理员杀死。在
为此,我使用APscheduler。在
代码在没有APscheduler的情况下运行得很好,但是当我尝试添加其余代码时,会发生两种情况之一:1)它永远运行,并且不会停止,尽管使用了“ctrl+C”,我需要使用任务管理器停止它;或者2)它只运行一次,然后停止运行
不会停止的代码:from apscheduler.scheduler import Scheduler
import logging
import time
logging.basicConfig()
sched = Scheduler()
sched.start()
(...)
code to make excel sheet and json file
(...)
@sched.interval_schedule(seconds = 15)
def job():
excelapi_final()
while True:
time.sleep(10)
sched.shutdown(wait=False)
一次后停止运行的代码:
^{pr2}$
我从其他问题、一些教程和文档中了解到,sched.shutdown应该允许通过ctrl+C终止代码,但是这不起作用。有什么想法吗?提前谢谢!在