APScheduler 未启动?
我想在晚上运行一个 python 脚本,所以我考虑使用 APScheduler。我将在第二天晚上 1 点开始运行它,它将每天晚上运行一次,
我的调度程序脚本如下所示 (scheduler.py):
from apscheduler.scheduler import Scheduler
from datetime import datetime, timedelta, time, date
def myScript():
print "ok"
if __name__ == '__main__':
sched = Scheduler()
startDate = datetime.combine(date.today() + timedelta(days=1),time(1))
sched.start()
sched.add_interval_job(myScript, start_date = startDate, days=1)
在 shell 中,我执行以下操作: python myScheduler.py & disown
(我正在远程运行它,所以我想在后台运行它并拒绝它。 立即,该行下方会出现一个数字 (PID),就像其他所有 Python 脚本一样。但是当我这样做时 ps -e | grep python,那个数字不存在。我尝试执行 kill -9 PID
并收到一条消息,指出该作业不存在。
调度程序是否正在运行?如果是的话,我该如何阻止它?如果不是,我做错了什么?
I would like to run a python script during the night and so I was thinking of using APScheduler. I'll start running it at 1am of the following night and it will run once every night
my scheduler script looks like this (scheduler.py):
from apscheduler.scheduler import Scheduler
from datetime import datetime, timedelta, time, date
def myScript():
print "ok"
if __name__ == '__main__':
sched = Scheduler()
startDate = datetime.combine(date.today() + timedelta(days=1),time(1))
sched.start()
sched.add_interval_job(myScript, start_date = startDate, days=1)
In the shell, I do:python myScheduler.py & disown
(I'm running it remotely, so I want to run it in the background and disown it.
Immediately, a number (PID) appears below the line, as every other python script would do. But when I do ps -e | grep python, that number is not there. I tried to do kill -9 PID
and I got a message saying that the job does not exist.
Is the scheduler running? If yes, how can I stop it? if not, what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您使用2.1.0版本,您还可以将standalone=True参数传递给Scheduler构造函数。详细文档可以在此处找到
If you use version 2.1.0, you can also pass standalone=True parameter to the Scheduler constructor. Detail documents can be found here
我认为你应该使用 阻塞调度程序如今。
I think you should use the blocking scheduler nowadays.
您必须保持脚本运行,否则在
sched.add_interval_job(myScript, start_date = startDate, days=1)
之后,脚本将结束并停止。添加一个
after,然后,调度程序仍然存在。
you have to keep the script running otherwise after the
sched.add_interval_job(myScript, start_date = startDate, days=1)
, the script ends and stop.add a
after, and then, the scheduler will still be alive.
正确的解决方案是告诉调度程序不要作为守护进程运行:
或者
The correct solution would be to tell the scheduler to not run as a daemon:
or
我安装了 apscheduler v3,这就是我要做的。
I have apscheduler v3 installed and this is what I would do.
这是我的方法:
here is my way: