2016-04-22 25 views
0

我目前的做法是首先删除旧模型,保存新模型,使用shell没有问题,但它只是不能自动使用crontab工作。任何想法为什么或如何解决这个问题?谢谢您的帮助。为什么我的python子进程调用在crontab中不起作用?

错误在于主程序不会等待subprocess.call返回。我认为这是问题,但不确定。

这是我目前的命令:

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

如何在crontab中设置路径?特别是,该路径中的'dse'可执行文件?检查你的日志! – dhke

+1

运行cron作业时,将stdout和stderr重定向到可以使用'command> cron.out 2>&1'读取的文件。然后,您可以阅读cron.out来查找实际错误是什么 – Spade

+0

@dhke和spade错误是主程序不会等待subprocess.call返回。我认为这是问题,但不确定。任何想法为什么? – peter

回答

1

一个可能的解决方案只是为了检查是否正确地执行是等待返回码。

下面的链接子模块: 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脚本执行> & 1> mickey.log

最后但并非最不重要的一些子/使用os.system建议可在这里: Controlling a python script from another script

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

请让我知道,如果这个解决您的问题。

+1

除了在WIN操作系统下使用subprocess.call(['python.exe',command,args]),您可能需要指定python才能执行调用,但这不是您的情况,因为我可以看到从命令:-)祝你有美好的一天。 –

相关问题