I have a strange problem with subprocess.CalledProcessError
when running my Django-project on a production server running Apache:
My code (UPDATE: added catch-all-exception handling - behaviour is unchanged) is as follows:
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
This is all working as expected when I run it on my Windows development machine and the djange testserver. The exception is caught when the command execution fails, the error handling works as expected.
When I move the code to my production server (ubuntu, apache), I get an "Internal Server Error 500" when the command execution fails which is not the desired behaviour. The apache error.log is not very helpful since it does not show any error.
My configuration is: Apache/2.2.22 (Ubuntu) PHP/5.4.9-4ubuntu2.3 mod_wsgi/3.4 Python/2.7.4
(Yes, I restarted apache and I'm sure I run on the same code).
Any ideas on this one?