]> SALOME platform Git repositories - tools/ydefx.git/commitdiff
Salome HOME
Add GIL management.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Fri, 1 Mar 2019 15:30:05 +0000 (16:30 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Fri, 1 Mar 2019 15:30:05 +0000 (16:30 +0100)
GIL management for JobParametersProxy and PyStudyFunction.
Some minor code formating changes.

15 files changed:
src/cpp/JobParametersProxy.cxx
src/cpp/JobParametersProxy.hxx
src/cpp/PyStudyFunction.cxx
src/cpp/PyStudyFunction.hxx
src/gui/ParamsConfig.cxx
src/gui/ParamsConfig.hxx
src/gui/PathsConfig.cxx
src/gui/PathsConfig.hxx
src/gui/QuickConfig.cxx
src/gui/QuickConfig.hxx
src/gui/ResourceWidget.cxx
src/gui/ResourceWidget.hxx
src/gui/ydefxgui.cxx
src/pydefx/configuration.py
src/pydefx/parameters.py

index 662b856216cfb94529de61e52b05c61b93e4ed36..c0ce84a7b269c2f5eb4d1110868a9c21a9b00ce0 100644 (file)
@@ -33,16 +33,52 @@ namespace ydefx
 JobParametersProxy::JobParametersProxy()
 :  _pyParameters(nullptr)
 {
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction objConstructor;
   objConstructor.loadExp("pydefx", "Parameters");
   _pyParameters = objConstructor();
 }
 
+JobParametersProxy::JobParametersProxy(const JobParametersProxy& copy)
+:  _pyParameters(nullptr)
+{
+  if(copy._pyParameters)
+  {
+    py2cpp::AutoGIL gil;
+    py2cpp::PyFunction deepCopyFn;
+    deepCopyFn.loadExp("copy", "deepcopy");
+    _pyParameters = deepCopyFn(copy._pyParameters);
+  }
+}
+
+JobParametersProxy::~JobParametersProxy()
+{
+  py2cpp::AutoGIL gil;
+  _pyParameters.reset(nullptr);
+}
+
+JobParametersProxy& JobParametersProxy::operator=(const JobParametersProxy& copy)
+{
+  if(this != &copy)
+  {
+    py2cpp::AutoGIL gil;
+    if(copy._pyParameters)
+    {
+      py2cpp::PyFunction deepCopyFn;
+      deepCopyFn.loadExp("copy", "deepcopy");
+      _pyParameters = deepCopyFn(copy._pyParameters);
+    }
+    else
+      _pyParameters.reset(nullptr);
+  }
+  return *this;
+}
 
 std::string
 JobParametersProxy::getAttrString(const std::string& attributeName)const
 {
   std::string result;
+  py2cpp::AutoGIL gil;
   py2cpp::pyResult(result) = _pyParameters.getAttr("salome_parameters")
                                           .getAttr(attributeName);
   return result;
@@ -52,6 +88,7 @@ void
 JobParametersProxy::setAttr(const std::string& attributeName,
                             const std::string& value)
 {
+  py2cpp::AutoGIL gil;
   _pyParameters.getAttr("salome_parameters")
                .setAttr(attributeName, py2cpp::toPyPtr(value));
 }
@@ -59,6 +96,7 @@ JobParametersProxy::setAttr(const std::string& attributeName,
 int JobParametersProxy::getResAttr(const std::string& attributeName)const
 {
   int result;
+  py2cpp::AutoGIL gil;
   py2cpp::pyResult(result) = _pyParameters.getAttr("salome_parameters")
                                           .getAttr("resource_required")
                                           .getAttr(attributeName);
@@ -67,6 +105,7 @@ int JobParametersProxy::getResAttr(const std::string& attributeName)const
 
 void JobParametersProxy::setResAttr(const std::string& attributeName, int value)
 {
+  py2cpp::AutoGIL gil;
   _pyParameters.getAttr("salome_parameters")
                .getAttr("resource_required")
                .setAttr(attributeName, py2cpp::toPyPtr(value));
@@ -124,6 +163,7 @@ void JobParametersProxy::env_file(const std::string& v)
 
 std::list<std::string> JobParametersProxy::in_files()const
 {
+  py2cpp::AutoGIL gil;
   std::list<std::string> result;
   py2cpp::pyResult(result) = _pyParameters.getAttr("salome_parameters")
                                           .getAttr("in_files");
@@ -146,6 +186,7 @@ void JobParametersProxy::remove_in_file(const std::string& path)
 
 void JobParametersProxy::in_files(const std::list<std::string>& pathList)
 {
+  py2cpp::AutoGIL gil;
   _pyParameters.getAttr("salome_parameters")
                .setAttr("in_files", py2cpp::toPyPtr(pathList));
 }
@@ -193,6 +234,7 @@ void JobParametersProxy::maximum_duration(const std::string& v)
 // ResourceParameters
 std::string JobParametersProxy::resource_name()const
 {
+  py2cpp::AutoGIL gil;
   std::string result;
   py2cpp::pyResult(result) = _pyParameters.getAttr("salome_parameters")
                                           .getAttr("resource_required")
@@ -202,6 +244,7 @@ std::string JobParametersProxy::resource_name()const
 
 void JobParametersProxy::resource_name(const std::string& name)
 {
+  py2cpp::AutoGIL gil;
   _pyParameters.getAttr("salome_parameters")
                .getAttr("resource_required")
                .setAttr("name", py2cpp::toPyPtr(name));
@@ -269,6 +312,7 @@ void JobParametersProxy::partition(const std::string& v)
 
 bool JobParametersProxy::exclusive()const
 {
+  py2cpp::AutoGIL gil;
   bool result;
   py2cpp::pyResult(result) = _pyParameters.getAttr("salome_parameters")
                                           .getAttr("exclusive");
@@ -277,12 +321,14 @@ bool JobParametersProxy::exclusive()const
 
 void JobParametersProxy::exclusive(bool v)
 {
+  py2cpp::AutoGIL gil;
   _pyParameters.getAttr("salome_parameters")
                .setAttr("exclusive", py2cpp::toPyPtr(v));
 }
 
 unsigned int JobParametersProxy::mem_per_cpu()const
 {
+  py2cpp::AutoGIL gil;
   int result;
   py2cpp::pyResult(result) = _pyParameters.getAttr("salome_parameters")
                                           .getAttr("mem_per_cpu");
@@ -293,6 +339,7 @@ unsigned int JobParametersProxy::mem_per_cpu()const
 
 void JobParametersProxy::mem_per_cpu(unsigned int v)
 {
+  py2cpp::AutoGIL gil;
   _pyParameters.getAttr("salome_parameters")
                .setAttr("mem_per_cpu", py2cpp::toPyPtr(v));
 }
@@ -320,6 +367,7 @@ void JobParametersProxy::extra_params(const std::string& v)
 
 unsigned int JobParametersProxy::nb_branches()const
 {
+  py2cpp::AutoGIL gil;
   unsigned int result;
   py2cpp::pyResult(result) = _pyParameters.getAttr("nb_branches");
   return result;
@@ -327,11 +375,13 @@ unsigned int JobParametersProxy::nb_branches()const
 
 void JobParametersProxy::nb_branches(unsigned int v)
 {
+  py2cpp::AutoGIL gil;
   _pyParameters.setAttr("nb_branches", py2cpp::toPyPtr(v));
 }
 
 void JobParametersProxy::configureResource(const std::string& resourceName)
 {
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp(_pyParameters, "configureResource");
   pyFn(resourceName);
@@ -339,13 +389,23 @@ void JobParametersProxy::configureResource(const std::string& resourceName)
 
 void JobParametersProxy::createResultDirectory(const std::string& basePath)
 {
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp(_pyParameters, "createResultDirectory");
   pyFn(basePath);
 }
 
+void JobParametersProxy::createTmpResultDirectory()
+{
+  py2cpp::AutoGIL gil;
+  py2cpp::PyFunction pyFn;
+  pyFn.loadExp(_pyParameters, "createTmpResultDirectory");
+  pyFn();
+}
+
 std::list<std::string> JobParametersProxy::AvailableResources()
 {
+  py2cpp::AutoGIL gil;
   std::list<std::string> result;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp("pydefx.configuration", "availableResources");
index 285bfd0beb7926ac561340ad1b99c0a17794e9f3..769bc4748e110ad2f8b406ee327d99476470218a 100644 (file)
@@ -29,6 +29,9 @@ class JobParametersProxy
 {
 public:
   JobParametersProxy();
+  JobParametersProxy(const JobParametersProxy& copy);
+  JobParametersProxy& operator=(const JobParametersProxy& copy);
+  ~JobParametersProxy();
 
   std::string job_name()const;
   void job_name(const std::string& v);
@@ -106,6 +109,8 @@ public:
   void configureResource(const std::string& resourceName);
   //! create a new result directory as a subdirectory of the given path.
   void createResultDirectory(const std::string& basePath);
+  //! create a new result directory in the system tmp
+  void createTmpResultDirectory();
 
   friend PyObject * py2cpp::toPy(const JobParametersProxy& jp);
   static std::list<std::string> AvailableResources();
index 96dedc2ee6684a221aee9c33fdd06c97c1639471..2ee90bc1c7407286f5bb8f50de60d89131e7d13a 100644 (file)
@@ -33,15 +33,50 @@ namespace ydefx
 PyStudyFunction::PyStudyFunction()
 : _pyObject(nullptr)
 {
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction objConstructor;
   objConstructor.loadExp("pydefx", "PyScript");
   _pyObject = objConstructor();
 }
 
-PyStudyFunction::~PyStudyFunction(){}
+PyStudyFunction::PyStudyFunction(const PyStudyFunction& copy)
+: _pyObject(nullptr)
+{
+  if(copy._pyObject)
+  {
+    py2cpp::AutoGIL gil;
+    py2cpp::PyFunction deepCopyFn;
+    deepCopyFn.loadExp("copy", "deepcopy");
+    _pyObject = deepCopyFn(copy._pyObject);
+  }
+}
+
+PyStudyFunction::~PyStudyFunction()
+{
+  py2cpp::AutoGIL gil;
+  _pyObject.reset(nullptr);
+}
+
+PyStudyFunction& PyStudyFunction::operator=(const PyStudyFunction& copy)
+{
+  if(this != &copy)
+  {
+    py2cpp::AutoGIL gil;
+    if(copy._pyObject)
+    {
+      py2cpp::PyFunction deepCopyFn;
+      deepCopyFn.loadExp("copy", "deepcopy");
+      _pyObject = deepCopyFn(copy._pyObject);
+    }
+    else
+      _pyObject.reset(nullptr);
+  }
+  return *this;
+}
 
 void PyStudyFunction::loadFile(const std::string& path)
 {
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp(_pyObject, "loadFile");
   pyFn(path);
@@ -49,6 +84,7 @@ void PyStudyFunction::loadFile(const std::string& path)
 
 void PyStudyFunction::loadString(const std::string& value)
 {
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp(_pyObject, "loadString");
   pyFn(value);
@@ -56,6 +92,7 @@ void PyStudyFunction::loadString(const std::string& value)
 
 void PyStudyFunction::save(const std::string& path)
 {
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp(_pyObject, "saveFile");
   pyFn(path);
@@ -64,6 +101,7 @@ void PyStudyFunction::save(const std::string& path)
 std::string PyStudyFunction::content()const
 {
   std::string result;
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp(_pyObject, "content");
   py2cpp::pyResult(result) = pyFn();
@@ -73,6 +111,7 @@ std::string PyStudyFunction::content()const
 std::list<std::string> PyStudyFunction::inputNames()const
 {
   std::list<std::string> result;
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp(_pyObject, "getInputNames");
   py2cpp::pyResult(result) = pyFn();
@@ -82,6 +121,7 @@ std::list<std::string> PyStudyFunction::inputNames()const
 std::list<std::string> PyStudyFunction::outputNames()const
 {
   std::list<std::string> result;
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp(_pyObject, "getOutputNames");
   py2cpp::pyResult(result) = pyFn();
@@ -91,6 +131,7 @@ std::list<std::string> PyStudyFunction::outputNames()const
 std::string PyStudyFunction::errors()const
 {
   std::string result;
+  py2cpp::AutoGIL gil;
   py2cpp::PyFunction pyFn;
   pyFn.loadExp(_pyObject, "getErrors");
   py2cpp::pyResult(result) = pyFn();
index df6dcdd1d93a735e26cfc27c5c30d245f0242d0c..e3e02a5496845e786322e2d6dbc262f052f53961 100644 (file)
@@ -27,6 +27,8 @@ class PyStudyFunction :  StudyFunction
 {
 public:
   PyStudyFunction();
+  PyStudyFunction(const PyStudyFunction& copy);
+  PyStudyFunction& operator=(const PyStudyFunction& copy);
   virtual ~PyStudyFunction();
   virtual void loadFile(const std::string& path);
   virtual void loadString(const std::string&);
index 3dbaa322d8900282ce67745b425aa03fc23ab026..bb52bf0d61bd5fe31f294a0c17c97b55c9b58c75 100644 (file)
@@ -18,6 +18,8 @@
 //
 #include "ParamsConfig.hxx"
 
+namespace ydefx
+{
 ParamsConfigWidget::ParamsConfigWidget(ydefx::JobParametersProxy& model,
                                        QWidget* parent)
 : QScrollArea(parent)
@@ -196,3 +198,4 @@ void ParamsConfigWidget::updateExtraParams()
   _model.extra_params(_extraEdit->toPlainText().toStdString());
 }
 
+}
index 22b78316e65ee863a819c83ab324623dc3ad1ab3..d461b3af581c55e0f7d09c20db02d47bfc5af905 100644 (file)
@@ -21,6 +21,8 @@
 #include "JobParametersProxy.hxx"
 #include <QtWidgets>
 
+namespace ydefx
+{
 class ParamsConfigWidget: public QScrollArea
 {
   Q_OBJECT
@@ -48,5 +50,5 @@ private:
   ydefx::JobParametersProxy& _model;
   QTextEdit * _extraEdit;
 };
-
+}
 #endif //IDEFX_ParamsConfigWidget_HXX
index 951fc9430fbc221f1181743709d18e0531e0c241..1ac57d83c8c82305aaa26322d128504b23b266ac 100644 (file)
@@ -18,6 +18,8 @@
 //
 #include "PathsConfig.hxx"
 
+namespace ydefx
+{
 PathsConfigWidget::PathsConfigWidget(ydefx::JobParametersProxy& model,
                                      QWidget* parent)
 : QScrollArea(parent)
@@ -184,3 +186,4 @@ void PathsConfigWidget::removeInputFiles()
     delete item;
   }
 }
+}
index bcc9722584cfdb96dcae8fff335c14518bfd22b6..f27ab4e5dfb69e2178dfe630883a12eda4ee6297 100644 (file)
@@ -21,6 +21,8 @@
 #include "JobParametersProxy.hxx"
 #include <QtWidgets>
 
+namespace ydefx
+{
 class PathsConfigWidget: public QScrollArea
 {
   Q_OBJECT
@@ -46,5 +48,5 @@ private:
   QListWidget * _inputFilesList;
   QPushButton *_removeInputFilesButton;
 };
-
+}
 #endif //IDEFX_PathsConfigWidget_HXX
index 40900b95368b22ad0e7e977263d20a7b035e5714..0282afbf26aa10d48f727b39f1eacee8030000c9 100644 (file)
@@ -18,6 +18,8 @@
 //
 #include "QuickConfig.hxx"
 
+namespace ydefx
+{
 QuickConfigWidget::QuickConfigWidget(ydefx::JobParametersProxy& model,
                                      QWidget* parent)
 : QScrollArea(parent)
@@ -77,3 +79,4 @@ void QuickConfigWidget::updateNbBranches(int value)
   _model.nb_branches(value);
   emit defaultNbBranches(value);
 }
+}
index 8f5398bd2723d8f0805b6090219f9398fb9fd96d..29bfb21431e9744b7bc12c45538efc9fcaf1cda5 100644 (file)
@@ -21,6 +21,8 @@
 #include "JobParametersProxy.hxx"
 #include <QtWidgets>
 
+namespace ydefx
+{
 class QuickConfigWidget: public QScrollArea
 {
   Q_OBJECT
@@ -39,5 +41,5 @@ signals:
 private:
   ydefx::JobParametersProxy& _model;
 };
-
+}
 #endif //IDEFX_QuickConfigWidget_HXX
index 967a833a35391a4c1ee026f7d8733da8c5f2b798..2e5c5a1e800f4d6994de7f763bb02c52a08a7a7c 100644 (file)
@@ -22,6 +22,8 @@
 #include "PathsConfig.hxx"
 #include "ParamsConfig.hxx"
 
+namespace ydefx
+{
 ResourceWidget::ResourceWidget(ydefx::JobParametersProxy& model,
                                QWidget* parent)
 : QTabWidget(parent)
@@ -44,3 +46,4 @@ ResourceWidget::ResourceWidget(ydefx::JobParametersProxy& model,
 ResourceWidget::~ResourceWidget()
 {
 }
+}
index a89f908fa2f4de592f166b5bca50aabc17adb819..cf8db53fbf7ec87185e7a9604ba4a7d8335035e1 100644 (file)
@@ -20,6 +20,8 @@
 #define IDEFX_RESOURCEWIDGET_HXX
 #include "JobParametersProxy.hxx"
 #include <QtWidgets>
+namespace ydefx
+{
 
 class ResourceWidget: public QTabWidget
 {
@@ -30,5 +32,5 @@ public:
 private:
   ydefx::JobParametersProxy& _model;
 };
-
+}
 #endif //IDEFX_RESOURCEWIDGET_HXX
index 96e4988843e78aed1d51b83f04c8dfe0d8c0c81b..9f05f1c988fdbc960306251d6c87b43ee3ce959c 100644 (file)
@@ -29,7 +29,7 @@ int main(int argc, char *argv[])
   {
     ydefx::JobParametersProxy jpp;
     jpp.createResultDirectory("/tmp");
-    ResourceWidget mygui(jpp);
+    ydefx::ResourceWidget mygui(jpp);
     mygui.show();
     ret = app.exec();
     std::cout << "job_name:" << jpp.job_name() << std::endl;
index 53ba752d9684035b4e5cd699cbccdcc3fbd79176..570cc8bdf561e556d63e8664f0fc8ae4b8ead8ab 100644 (file)
@@ -46,7 +46,7 @@ def newResultDirectory(basedir=None):
 def defaultWckey(resource="localhost"):
   result = ""
   if resource != "localhost":
-    result = "P11U5:CARBONES"
+    result = "P11N0:SALOME"
   return result
 
 def availableResources():
index 4167973bad6ea9248652013b05acb7dcc87e1e51..52a1ade532a4e67b96c116047de7cf20ae69def4 100644 (file)
@@ -19,6 +19,7 @@
 #
 import salome
 from . import configuration
+import tempfile
 
 class Parameters:
   def __init__(self, resource="localhost",
@@ -52,4 +53,9 @@ class Parameters:
     self.salome_parameters.wckey = configuration.defaultWckey(resource)
 
   def createResultDirectory(self, result_base_dir):
-    self.salome_parameters.result_directory = configuration.newResultDirectory(result_base_dir)
+    self.salome_parameters.result_directory = configuration.newResultDirectory(
+                                                                result_base_dir)
+
+  def createTmpResultDirectory(self):
+    self.salome_parameters.result_directory = configuration.newResultDirectory(
+                                                          tempfile.gettempdir())