in benchmarking/utils/subprocess_with_logger.py [0:0]
def _processRun(*args, **kwargs):
if not kwargs.get("silent", False):
getLogger().info(">>>>>> Running: %s", " ".join(*args))
err_output = None
try:
run_async = False
if "async" in kwargs:
run_async = kwargs["async"]
non_blocking = False
if "non_blocking" in kwargs and kwargs["non_blocking"]:
non_blocking = True
if non_blocking:
_Popen(*args, **kwargs)
return [], None
timeout = None
if "timeout" in kwargs:
timeout = kwargs["timeout"]
ps = _Popen(*args, **kwargs)
t = None
if timeout:
t = Timer(timeout, _kill, [ps, " ".join(*args), kwargs["process_key"]])
t.start()
if run_async:
# when running the process asyncronously we return the
# popen object and timer for the timeout as a tuple
# it is the responsibility of the caller to pass this
# tuple into processWait in order to gather the output
# from the process
return (ps, t), None
return processWait((ps, t), **kwargs)
except subprocess.CalledProcessError as e:
err_output = e.output.decode("utf-8", errors="replace")
getLogger().error("Command failed: {}".format(err_output))
except Exception:
getLogger().error(
"Unknown exception {}: {}".format(sys.exc_info()[0], " ".join(*args))
)
err_output = "{}".format(sys.exc_info()[0])
setRunStatus(1, key=kwargs["process_key"])
return [], err_output