From cede188e76004b2f58106229b3823e30c111b8ef Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 7 Jun 2019 17:51:27 +0200 Subject: [PATCH] enable to explicitly set the environment required for running MPI processes when mpi4py is imported --- python/damask/test/test.py | 2 +- python/damask/util.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/python/damask/test/test.py b/python/damask/test/test.py index e2ef89330..e7f2da14a 100644 --- a/python/damask/test/test.py +++ b/python/damask/test/test.py @@ -267,7 +267,7 @@ class Test(): logging.critical('Current2Current: Unable to copy file "{}"'.format(f)) raise - def execute_inCurrentDir(self,cmd,streamIn=None): + def execute_inCurrentDir(self,cmd,streamIn=None,env=None): logging.info(cmd) out,error = damask.util.execute(cmd,streamIn,self.dirCurrent()) diff --git a/python/damask/util.py b/python/damask/util.py index 189f08a98..27babf43f 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -97,14 +97,17 @@ def strikeout(what): # ----------------------------- def execute(cmd, streamIn = None, - wd = './'): + wd = './', + env = None): """Executes a command in given directory and returns stdout and stderr for optional stdin""" initialPath = os.getcwd() os.chdir(wd) + myEnv = os.environ if env is None else env process = subprocess.Popen(shlex.split(cmd), stdout = subprocess.PIPE, stderr = subprocess.PIPE, - stdin = subprocess.PIPE) + stdin = subprocess.PIPE, + env = myEnv) out,error = [i for i in (process.communicate() if streamIn is None else process.communicate(streamIn.read().encode('utf-8')))] out = out.decode('utf-8').replace('\x08','')