Apscheduler 脚本文件静默停止 - 没有错误
Apscheduler script file stops silently - no error
我有一个 scheduler_project.py
脚本文件。
代码:
from apscheduler.schedulers.background import BackgroundScheduler
scheduler = BackgroundScheduler()
def func_1():
# updating file-1
def func_2():
# updating file-2
scheduler.add_job(func_1, 'cron', hour='10-23' , minute='0-58', second=20)
scheduler.add_job(func_2, 'cron', hour='1')
scheduler.start()
当我 运行,(在 Windows 机器上)
E:\> python scheduler_project.py
E:\> # there is no error
在日志中:(我在调试级别的上面代码中添加了 logging
)
It says, job is added and starts in (some x seconds), but it is not
starting.
在任务管理器中,命令提示符进程显示一秒钟后消失。
而且我的文件也没有得到更新,这是显而易见的。
发生了什么事?执行此调度程序脚本的正确方法是什么?
Scheduler 是为 运行 与其他代码一起创建的 - 因此在启动 scheduler 之后,您可以 运行 其他代码。
如果你没有任何其他工作,那么你必须一直使用一些循环来运行它。
在documentation you can see link to examples on GitHub and one of example中使用
while True:
time.sleep(2)
我有一个 scheduler_project.py
脚本文件。
代码:
from apscheduler.schedulers.background import BackgroundScheduler
scheduler = BackgroundScheduler()
def func_1():
# updating file-1
def func_2():
# updating file-2
scheduler.add_job(func_1, 'cron', hour='10-23' , minute='0-58', second=20)
scheduler.add_job(func_2, 'cron', hour='1')
scheduler.start()
当我 运行,(在 Windows 机器上)
E:\> python scheduler_project.py
E:\> # there is no error
在日志中:(我在调试级别的上面代码中添加了 logging
)
It says, job is added and starts in (some x seconds), but it is not starting.
在任务管理器中,命令提示符进程显示一秒钟后消失。
而且我的文件也没有得到更新,这是显而易见的。
发生了什么事?执行此调度程序脚本的正确方法是什么?
Scheduler 是为 运行 与其他代码一起创建的 - 因此在启动 scheduler 之后,您可以 运行 其他代码。
如果你没有任何其他工作,那么你必须一直使用一些循环来运行它。
在documentation you can see link to examples on GitHub and one of example中使用
while True:
time.sleep(2)