Unverified Commit 8cd264fd authored by guoshzhao's avatar guoshzhao Committed by GitHub
Browse files

Benchmarks: Code Revision - Revise subprocess invoke (#178)

**Description**
Package frequently-used subprocess invoke into function.
parent b97197f0
......@@ -4,12 +4,11 @@
"""Module of the micro-benchmark base class."""
import os
import subprocess
import shutil
import statistics
from abc import abstractmethod
from superbench.common.utils import logger
from superbench.common.utils import logger, run_command
from superbench.benchmarks import BenchmarkType, ReturnCode
from superbench.benchmarks.base import Benchmark
......@@ -170,14 +169,8 @@ def _benchmark(self):
self._curr_run_index, self._name, self._commands[cmd_idx]
)
)
output = subprocess.run(
self._commands[cmd_idx],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,
check=False,
universal_newlines=True
)
output = run_command(self._commands[cmd_idx])
if output.returncode != 0:
self._result.set_return_code(ReturnCode.MICROBENCHMARK_EXECUTION_FAILURE)
logger.error(
......
......@@ -6,6 +6,7 @@
from superbench.common.utils.logging import SuperBenchLogger, logger
from superbench.common.utils.file_handler import rotate_dir, create_sb_output_dir, get_sb_config
from superbench.common.utils.lazy_import import LazyImport
from superbench.common.utils.process import run_command
nv_helper = LazyImport('superbench.common.utils.nvidia_helper')
......@@ -18,4 +19,5 @@
'network',
'nv_helper',
'rotate_dir',
'run_command',
]
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Process Utility."""
import subprocess
def run_command(command):
"""Run command in string format, return the result with stdout and stderr.
Args:
command (str): command to run.
Return:
result (subprocess.CompletedProcess): The return value from subprocess.run().
"""
result = subprocess.run(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, check=False, universal_newlines=True
)
return result
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment