简体   繁体   English

Apscheduler 脚本文件静默停止 - 没有错误

[英]Apscheduler script file stops silently - no error

I have a scheduler_project.py script file.我有一个scheduler_project.py脚本文件。

code:代码:

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()

When I run, (on Windows machine)当我运行时,(在 Windows 机器上)

E:\> python scheduler_project.py 
E:\>                            # there is no error

In Log: (I have added logging in above code at debug level)在日志中:(我在调试级别添加了上面代码的logging

It says, job is added and starts in (some x seconds), but it is not starting.它说,作业已添加并在(一些 x 秒)内开始,但它没有开始。

In task manager, the command prompt process display for a second and disappear.在任务管理器中,命令提示符进程显示一秒钟然后消失。

And my files are also not getting updated, which is obvious.而且我的文件也没有更新,这很明显。

What's happening?发生了什么? What is the right way to execute this scheduler script?执行此调度程序脚本的正确方法是什么?

Scheduler was created to run with other code - so after starting scheduler you can run other code.调度程序被创建为与其他代码一起运行 - 因此在启动调度程序后您可以运行其他代码。

If you don't have any other job then you have to use some loop to run it all time.如果你没有任何其他工作,那么你必须使用一些循环来一直运行它。

In documentation you can see link to examples on GitHub and one of example uses文档中,您可以看到 GitHub 上示例的链接和示例用途之一

while True:
    time.sleep(2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM