2016-04-22 45 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才能執行調用,但這不是您的情況,因爲我可以看到從命令:-)祝你有美好的一天。 –