GIL management for JobParametersProxy and PyStudyFunction.
Some minor code formating changes.
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 != ©)
+ {
+ 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;
JobParametersProxy::setAttr(const std::string& attributeName,
const std::string& value)
{
+ py2cpp::AutoGIL gil;
_pyParameters.getAttr("salome_parameters")
.setAttr(attributeName, py2cpp::toPyPtr(value));
}
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);
void JobParametersProxy::setResAttr(const std::string& attributeName, int value)
{
+ py2cpp::AutoGIL gil;
_pyParameters.getAttr("salome_parameters")
.getAttr("resource_required")
.setAttr(attributeName, py2cpp::toPyPtr(value));
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");
void JobParametersProxy::in_files(const std::list<std::string>& pathList)
{
+ py2cpp::AutoGIL gil;
_pyParameters.getAttr("salome_parameters")
.setAttr("in_files", py2cpp::toPyPtr(pathList));
}
// ResourceParameters
std::string JobParametersProxy::resource_name()const
{
+ py2cpp::AutoGIL gil;
std::string result;
py2cpp::pyResult(result) = _pyParameters.getAttr("salome_parameters")
.getAttr("resource_required")
void JobParametersProxy::resource_name(const std::string& name)
{
+ py2cpp::AutoGIL gil;
_pyParameters.getAttr("salome_parameters")
.getAttr("resource_required")
.setAttr("name", py2cpp::toPyPtr(name));
bool JobParametersProxy::exclusive()const
{
+ py2cpp::AutoGIL gil;
bool result;
py2cpp::pyResult(result) = _pyParameters.getAttr("salome_parameters")
.getAttr("exclusive");
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");
void JobParametersProxy::mem_per_cpu(unsigned int v)
{
+ py2cpp::AutoGIL gil;
_pyParameters.getAttr("salome_parameters")
.setAttr("mem_per_cpu", py2cpp::toPyPtr(v));
}
unsigned int JobParametersProxy::nb_branches()const
{
+ py2cpp::AutoGIL gil;
unsigned int result;
py2cpp::pyResult(result) = _pyParameters.getAttr("nb_branches");
return result;
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);
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");
{
public:
JobParametersProxy();
+ JobParametersProxy(const JobParametersProxy& copy);
+ JobParametersProxy& operator=(const JobParametersProxy& copy);
+ ~JobParametersProxy();
std::string job_name()const;
void job_name(const std::string& v);
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();
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 != ©)
+ {
+ 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);
void PyStudyFunction::loadString(const std::string& value)
{
+ py2cpp::AutoGIL gil;
py2cpp::PyFunction pyFn;
pyFn.loadExp(_pyObject, "loadString");
pyFn(value);
void PyStudyFunction::save(const std::string& path)
{
+ py2cpp::AutoGIL gil;
py2cpp::PyFunction pyFn;
pyFn.loadExp(_pyObject, "saveFile");
pyFn(path);
std::string PyStudyFunction::content()const
{
std::string result;
+ py2cpp::AutoGIL gil;
py2cpp::PyFunction pyFn;
pyFn.loadExp(_pyObject, "content");
py2cpp::pyResult(result) = pyFn();
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();
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();
std::string PyStudyFunction::errors()const
{
std::string result;
+ py2cpp::AutoGIL gil;
py2cpp::PyFunction pyFn;
pyFn.loadExp(_pyObject, "getErrors");
py2cpp::pyResult(result) = pyFn();
{
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&);
//
#include "ParamsConfig.hxx"
+namespace ydefx
+{
ParamsConfigWidget::ParamsConfigWidget(ydefx::JobParametersProxy& model,
QWidget* parent)
: QScrollArea(parent)
_model.extra_params(_extraEdit->toPlainText().toStdString());
}
+}
#include "JobParametersProxy.hxx"
#include <QtWidgets>
+namespace ydefx
+{
class ParamsConfigWidget: public QScrollArea
{
Q_OBJECT
ydefx::JobParametersProxy& _model;
QTextEdit * _extraEdit;
};
-
+}
#endif //IDEFX_ParamsConfigWidget_HXX
//
#include "PathsConfig.hxx"
+namespace ydefx
+{
PathsConfigWidget::PathsConfigWidget(ydefx::JobParametersProxy& model,
QWidget* parent)
: QScrollArea(parent)
delete item;
}
}
+}
#include "JobParametersProxy.hxx"
#include <QtWidgets>
+namespace ydefx
+{
class PathsConfigWidget: public QScrollArea
{
Q_OBJECT
QListWidget * _inputFilesList;
QPushButton *_removeInputFilesButton;
};
-
+}
#endif //IDEFX_PathsConfigWidget_HXX
//
#include "QuickConfig.hxx"
+namespace ydefx
+{
QuickConfigWidget::QuickConfigWidget(ydefx::JobParametersProxy& model,
QWidget* parent)
: QScrollArea(parent)
_model.nb_branches(value);
emit defaultNbBranches(value);
}
+}
#include "JobParametersProxy.hxx"
#include <QtWidgets>
+namespace ydefx
+{
class QuickConfigWidget: public QScrollArea
{
Q_OBJECT
private:
ydefx::JobParametersProxy& _model;
};
-
+}
#endif //IDEFX_QuickConfigWidget_HXX
#include "PathsConfig.hxx"
#include "ParamsConfig.hxx"
+namespace ydefx
+{
ResourceWidget::ResourceWidget(ydefx::JobParametersProxy& model,
QWidget* parent)
: QTabWidget(parent)
ResourceWidget::~ResourceWidget()
{
}
+}
#define IDEFX_RESOURCEWIDGET_HXX
#include "JobParametersProxy.hxx"
#include <QtWidgets>
+namespace ydefx
+{
class ResourceWidget: public QTabWidget
{
private:
ydefx::JobParametersProxy& _model;
};
-
+}
#endif //IDEFX_RESOURCEWIDGET_HXX
{
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;
def defaultWckey(resource="localhost"):
result = ""
if resource != "localhost":
- result = "P11U5:CARBONES"
+ result = "P11N0:SALOME"
return result
def availableResources():
#
import salome
from . import configuration
+import tempfile
class Parameters:
def __init__(self, resource="localhost",
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())