self.myScript = pydefx.PyScript()
self.mySample = None
self.myParams = params
+ self.removeTmpDir = False
+
+ def getResultDirectory(self):
+ return self.myParams.salome_parameters.result_directory
def map(self, func, iterable):
if len(iterable) == 0:
ret = [elt for elt in zip(*[self.myStudy.sample._output[n] for n in self.myStudy.sample.getOutputNames()])]
if len(self.myStudy.sample.getOutputNames()) == 1:
ret = [elt[0] for elt in ret]
+ self.removeTmpDir = True
return ret
else:
excMsg = "\n".join(["Error for sample # {} : \'{}\' ".format(i,elt) for i,elt in enumerate(messageFromSlaves) if elt != ""])
- raise RuntimeError( excMsg )
+ excMsg += "\nDirectory containing information for debug : {}".format(self.getResultDirectory())
+ exc = RuntimeError( excMsg )
+ exc.tmp_dir = self.getResultDirectory()
+ raise exc
else:
raise RuntimeError("Error during job submission or during the driver execution (that should never happend)")
return self
def __exit__(self, exc_type, exc_val, exc_tb):
+ import os
+ from glob import glob
+ import shutil
+ if self.removeTmpDir:
+ for fn in glob(os.path.join(self.getResultDirectory(),"*")):
+ if os.path.isdir( fn ):
+ shutil.rmtree( fn)
+ else:
+ os.unlink( fn )
pass
pass
def init(resourceName, resultDirectory = "/tmp"):
"""
-
Instanciate a pydefx.Parameters intance that can be overriden right after.
Here some example of typical override of the returned object of this method :
test_insitu.py
test_prescript.py
test_default.py
+ test_mpmcn.py
)
INSTALL(FILES ${TESTFILES} DESTINATION ${LOCAL_TEST_DIR})
INSTALL(PROGRAMS runUnitTest.sh
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-python3 -m unittest test_insitu.py test_prescript.py test_default.py
-ret=$?
+python3 -m unittest test_insitu.py test_prescript.py test_default.py
+ret0=$?
+python3 test_mpmcn.py
+ret1=$?
+let ret=$ret0+$ret1
exit $ret
--- /dev/null
+
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+
+# multiple processes on multiple compute nodes
+
+def f(x):
+ return x*x*x
+
+def f2(x):
+ if x==3:
+ raise RuntimeError("lllll")
+ return x*x*x
+
+import mpmcn
+
+def gg():
+ # case 0 : normal behavior with no raise
+ params = mpmcn.init("localhost")
+ with mpmcn.Pool(params) as p:
+ res = p.map(f,list(range(10)))
+ # getResultDirectory : for advanced users
+ p.getResultDirectory()
+ if res != [0.0, 1.0, 8.0, 27.0, 64.0, 125.0, 216.0, 343.0, 512.0, 729.0]:
+ raise RuntimeError("Test Failed !")
+ # case 1 : behavior with raise
+ params = mpmcn.init("localhost")
+ with mpmcn.Pool(params) as p2:
+ try:
+ res = p2.map(f2,list(range(10)))
+ raise RuntimeError("Exception not thrown -> Error !")
+ except RuntimeError as e:
+ strExpected = "Error for sample # 3 : \'lllll\'"
+ # tmp_dir attr of e returns the ResultDirectory to dive into
+ if str(e)[:len(strExpected)] != strExpected or not hasattr(e,"tmp_dir"):
+ raise RuntimeError("Test Failed 2 !")
+
+if __name__ == "__main__":
+ gg()