Wrap exceptions that occur while running external process

This should help identify problem with timeouts.

Change-Id: I663b1ca3fe9a74ed0869fefdb16583951e3db6a5
This commit is contained in:
Yuriy Taraday
2014-02-13 13:44:19 +04:00
parent 9a7f8ad613
commit d3e2986fa1

View File

@@ -15,6 +15,7 @@
import os
import subprocess
import traceback
def run_cmd(*args, **kwargs):
@@ -25,6 +26,7 @@ def run_cmd(*args, **kwargs):
def preexec_fn():
return os.chdir(kwargs['chdir'])
try:
proc = subprocess.Popen(args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, env=os.environ,
@@ -36,6 +38,11 @@ def run_cmd(*args, **kwargs):
out, err = proc.communicate()
out = out.decode('utf-8')
except Exception:
raise Exception(
"Exception while processing the command:\n%s.\n%s" %
(' '.join(args), traceback.format_exc())
)
if proc.returncode != 0:
raise Exception(