--- /dev/null
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Copyright (C) 2022 EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
+import pydefx
+
+myParams = None
+
+class Pool:
+ def __init__(self):
+ self.myStudy = None
+ self.myScript = pydefx.PyScript()
+ self.mySample = None
+
+ def map(self, func, iterable):
+ global myParams
+ if len(iterable) == 0:
+ return []
+ #
+ import inspect
+ if not inspect.isfunction(func):
+ raise RuntimeError("Input is expected to be a function")
+ import importlib
+ fModule = importlib.import_module(func.__module__)
+ if fModule == "__main__":
+ raise RuntimeError("Input function is expected to be part of a module")
+ st = None
+ with open(fModule.__file__,"r") as ff:
+ st = ff.read()
+ fStr = func.__code__.co_name
+ """fStr = None
+ for elt in dir(fModule):
+ if eval(elt) == f:
+ fStr = elt
+ print(fStr)
+ break"""
+ if fStr is None:
+ raise RuntimeError("Impossible to locate function in the module containing it !")
+ fArgs = inspect.getfullargspec(func).args
+ pyScript = """{}
+def _exec({}):
+ yxyx = {}({})
+ return yxyx
+""".format(st,", ".join(fArgs),fStr,", ".join(fArgs))
+ #
+ self.myScript.loadString(pyScript)
+ self.mySample = self.myScript.CreateEmptySample()
+ #
+ #print(fArgs)
+ #print(iterable)
+ #
+ if not hasattr(iterable[0],"__iter__"):
+ iterable = [[elt] for elt in iterable]
+ #
+ #print(pyScript)
+ #print({k:v for k,*v in zip(fArgs,*iterable)})
+ #
+ self.mySample.setInputValues( {k:v for k,*v in zip(fArgs,*iterable)} )
+ #
+ self.myStudy.createNewJob(self.myScript, self.mySample, myParams)
+ #
+ self.myStudy.launch()
+ self.myStudy.wait()
+ #
+ return self.myStudy.getResult()
+
+ def __enter__(self):
+ self.myStudy = pydefx.PyStudy()
+ return self
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ pass
+ pass
+
+def init(resultDirectory = "/tmp"):
+ """
+ :param resourceName: Name of the resource matching one of the ${KERNEL_ROOT_DIR}/share/salome/resources/kernel/CatalogResources.xml
+ :param resultDirectory: Directory used to transfer results
+ """
+ global myParams
+ myParams = pydefx.Parameters()
+ myParams.configureResource("localhost")
+ myParams.createResultDirectory(resultDirectory)
+ pass
+