【发布时间】:2016-07-27 23:13:09
【问题描述】:
我有一个运行我的网站的亚马逊实例。我最近尝试设置一个 cron 作业,它只是停止而不会在任务中途抛出任何错误或任何东西。
crontab -l 显示
30 13 * * 1,2,3,4,5,6 /home/ubuntu/.virtualenvs/testprep/bin/python /home/ubuntu/web/testprep/manage.py daily > /tmp/prepcron.log
这是我的 python/django 脚本:
class Command(BaseCommand):
def handle(self, *args, **options):
print("starting")
date = datetime.now().date()
print("date is", date)
try:
users = User.objects.filter(test="ACT", state__in=[User.WAITING, User.READY, User.SOLUTION])
except Exception as e:
print(str(e))
print("number of users", users.count())
...
在 13:30,我在我的日志文件中得到了这个:
starting
date is 2016-07-19
就是这样!没有错误被抛出或捕获。 Number of users 永远不会被打印出来。该程序只是中途放弃。如果我手动运行该命令(文字复制和粘贴),那么脚本会按预期执行,这只会在我尝试安排它时发生。
有人见过这样的吗?
【问题讨论】:
-
程序还在运行吗?是不是挂在过滤器上了?这将是我能想到的唯一原因,不仅不抛出异常,而且不打印用户数量。
-
如果它还在运行,它现在已经运行了几个小时。我该如何检查?
-
做一个
ps aux | grep "SCRIPTNAME"编辑:SCRIPTNAME 应该是(从你的命令)manage.py,所以ps aux | grep "manage.py" -
ubuntu 21833 0.0 0.0 10460 948 pts/0 S+ 19:29 0:00 grep --color=auto manage.py是什么意思? -
如果你注意到,命令以“grep --color auto manage.py”结尾,这意味着你得到的搜索结果是进程列表的结果。如果这是您从进程列表中唯一的输出,那么它还没有挂起。