subprocess.CalledProcessError
Apache を実行しているプロダクション サーバーで Django プロジェクトを実行すると、奇妙な問題が発生します。
私のコード(更新:catch-all-exception処理が追加されました-動作は変更されていません)は次のとおりです。
try:
command_string = 'gcc -O0 -g3 -Wall -c -fmessage-length=0 ' + cfile + ' -o ' + ofile
compile_result = subprocess.check_output(command_string,stderr=subprocess.STDOUT,shell=True)
#logger.warning(compile_result)
if compile_result != "": #Dann gab es einen Fehler bzw. ein Compiler-Warning --> Abbruch!
self.ausgabe = u"Compile:\n"
self.ausgabe += unicode(compile_result, "utf-8")
return
except subprocess.CalledProcessError as e:
self.ausgabe = u"Compilierfehler (Returncode {0}):\n".format(e.returncode)
self.ausgabe += unicode(e.output, "utf-8")
logger.error("CPE" + unicode(e.returncode, "utf-8") + unicode(e.output, "utf-8"))
return #die weiteren Schritte müssen gar nicht erst ausgeführt werden...
except:
logger.error(str(sys.exc_info()))
self.ausgabe = u"Compilieren nicht erfolgreich. Fehler:\n" + unicode(sys.exc_info(), "utf-8")
return
Windows 開発マシンと djange テストサーバーで実行すると、これはすべて期待どおりに機能します。コマンドの実行が失敗したときに例外がキャッチされ、エラー処理が期待どおりに機能します。
コードを実稼働サーバー (ubuntu、apache) に移動すると、コマンドの実行が失敗したときに「Internal Server Error 500」が発生しますが、これは望ましい動作ではありません。Apache の error.log にはエラーが表示されないため、あまり役に立ちません。
私の構成は次のとおりです。 Apache/2.2.22 (Ubuntu) PHP/5.4.9-4ubuntu2.3 mod_wsgi/3.4 Python/2.7.4
(はい、Apache を再起動しましたが、同じコードで実行していると確信しています)。
これに関するアイデアはありますか?