in src/sagemaker_training/process.py [0:0]
def check_error(cmd, error_class, processes_per_host, cwd=None, capture_error=True, **kwargs):
"""Run a commmand, raising an exception if there is an error.
Args:
cmd ([str]): The command to be run.
error_class (cls): The class to use when raising an exception.
processes_per_host (int): Number of processes per host
capture_error (bool): Whether or not to include stderr in
the exception message (default: True). In either case,
stderr is streamed to the process's output.
**kwargs: Extra arguments that are passed to the subprocess.Popen constructor.
Returns:
subprocess.Popen: The process for the given command.
Raises:
error_class: If there is an exception raised when creating the process.
"""
if capture_error:
return_code, output, process = create(
cmd,
error_class,
processes_per_host,
env=os.environ,
cwd=cwd or environment.code_dir,
capture_error=True,
**kwargs,
)
stderr = output[1]
else:
stderr = None
process = subprocess.Popen(
cmd, env=os.environ, cwd=cwd or environment.code_dir, stderr=stderr, **kwargs
)
return_code = process.wait()
if return_code:
extra_info = None
if return_code == 137:
extra_info = "OutOfMemory: Process killed by SIGKILL (signal 9)"
raise error_class(
cmd=" ".join(cmd) if isinstance(cmd, list) else cmd,
return_code=return_code,
output=stderr,
info=extra_info,
)
return process