From a984eadab3e71f8ae8e49910b506d8d02bc0ee07 Mon Sep 17 00:00:00 2001 From: Matthew Drozt Date: Tue, 17 May 2022 19:20:24 -0400 Subject: [PATCH] Mpiexec Patch (#192) Updates the MpiexecSettings (and all other OpenMPI settings classes) to use `subprocess.run` as opposed to `subprocess.check_output` when checking version statements so that it can handle a non-zero status return code. [ committed by @MattToast ] [ reviewed by @al-rigazzi @Spartee ] --- smartsim/settings/mpirunSettings.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/smartsim/settings/mpirunSettings.py b/smartsim/settings/mpirunSettings.py index 5fa102ea4..1647c49be 100644 --- a/smartsim/settings/mpirunSettings.py +++ b/smartsim/settings/mpirunSettings.py @@ -24,7 +24,7 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import subprocess as sp +import subprocess import re from ..error import SSUnsupportedError @@ -268,8 +268,12 @@ def __init__(self, exe, exe_args=None, run_args=None, env_vars=None, **kwargs): """ super().__init__(exe, exe_args, "mpirun", run_args, env_vars, **kwargs) - version_stmt = sp.check_output([self.run_command, "-V"]).decode() - if not re.match(r"mpirun\s\(Open MPI\)\s4.\d+.\d+", version_stmt): + completed_process = subprocess.run( + [self.run_command, "-V"], capture_output=True + ) # type: subprocess.CompletedProcess + version_statement = completed_process.stdout.decode() + + if not re.match(r"mpirun\s\(Open MPI\)\s4.\d+.\d+", version_statement): logger.warning("Non-OpenMPI implementation of `mpirun` detected") @@ -296,8 +300,12 @@ def __init__(self, exe, exe_args=None, run_args=None, env_vars=None, **kwargs): """ super().__init__(exe, exe_args, "mpiexec", run_args, env_vars, **kwargs) - version_stmt = sp.check_output([self.run_command, "-V"]).decode() - if not re.match(r"mpiexec\s\(OpenRTE\)\s4.\d+.\d+", version_stmt): + completed_process = subprocess.run( + [self.run_command, "-V"], capture_output=True + ) # type: subprocess.CompletedProcess + version_statement = completed_process.stdout.decode() + + if not re.match(r"mpiexec\s\(OpenRTE\)\s4.\d+.\d+", version_statement): logger.warning("Non-OpenMPI implementation of `mpiexec` detected") @@ -324,6 +332,10 @@ def __init__(self, exe, exe_args=None, run_args=None, env_vars=None, **kwargs): """ super().__init__(exe, exe_args, "orterun", run_args, env_vars, **kwargs) - version_stmt = sp.check_output([self.run_command, "-V"]).decode() - if not re.match(r"orterun\s\(OpenRTE\)\s4.\d+.\d+", version_stmt): + completed_process = subprocess.run( + [self.run_command, "-V"], capture_output=True + ) # type: subprocess.CompletedProcess + version_statement = completed_process.stdout.decode() + + if not re.match(r"orterun\s\(OpenRTE\)\s4.\d+.\d+", version_statement): logger.warning("Non-OpenMPI implementation of `orterun` detected")