我的python子进程调用在crontab中不起作用为什么?

2024-06-17 00:57:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前的方法是先删除旧模型,保存新模型,使用shell是没有问题的,但是它不能自动使用crontab工作。你知道为什么或者怎么解决这个问题吗?谢谢你的帮助。在

错误是主程序没有等待subprocess.call回来。我认为这就是问题所在,但不确定。在

这是我当前的命令:

subprocess.call('dse hadoop fs -rmr /root/recommend_model', shell=True)  

Tags: 方法模型命令hadoop错误rootshellcall
1条回答
网友
1楼 · 发布于 2024-06-17 00:57:54

检查是否正确执行的一个可能的解决方案是等待返回代码。在

下面是指向子流程模块的链接: https://docs.python.org/2/library/subprocess.html

您可以等待脚本中的返回代码:

if (subprocess.call(command, args) == 0):
    print("We are proceeding)
else:
    print("Something went wrong executing %s" % command)

另外,根据建议尝试使用2 gt;1>;重定向到脚本执行的日志文件;米奇.log在

最后但并非最不重要的一些子流程/操作系统此处提供建议: Controlling a python script from another script

python: run external program and direct output to file and wait for finish

如果这能解决你的问题,请告诉我。在

相关问题 更多 >