Version: 8.3.0
YACS::ENGINE::PythonEntry Class Referenceabstract

#include <PythonNode.hxx>

Inheritance diagram for YACS::ENGINE::PythonEntry:
Collaboration diagram for YACS::ENGINE::PythonEntry:

Static Public Attributes

static const char SCRIPT_FOR_SIMPLE_SERIALIZATION []
 

Protected Member Functions

 PythonEntry ()
 
 ~PythonEntry ()
 
virtual void assignRemotePyInterpretor (Engines::PyNodeBase_var remoteInterp)=0
 
virtual Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny (Engines::Container_ptr objContainer) const =0
 returns (if any) an object, you have to deal with (UnRegister) More...
 
virtual void createRemoteAdaptedPyInterpretor (Engines::Container_ptr objContainer)=0
 returns an object, you have to deal with (UnRegister) More...
 
virtual Engines::PyNodeBase_var getRemoteInterpreterHandle ()=0
 
virtual const char * getSerializationScript () const =0
 
void commonRemoteLoad (InlineNode *reqNode)
 
void commonRemoteLoadPart1 (InlineNode *reqNode)
 
Engines::Container_var commonRemoteLoadPart2 (InlineNode *reqNode, bool &isInitializeRequested)
 
void commonRemoteLoadPart3 (InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested)
 

Static Protected Member Functions

static std::string GetContainerLog (const std::string &mode, Container *container, const Task *askingTask)
 

Protected Attributes

PyObject * _context
 
PyObject * _pyfuncSer
 
PyObject * _pyfuncUnser
 
PyObject * _pyfuncSimpleSer
 

Detailed Description

Definition at line 35 of file PythonNode.hxx.

Constructor & Destructor Documentation

PythonEntry::PythonEntry ( )
protected

Definition at line 80 of file PythonNode.cxx.

81 {
82 }
PythonEntry::~PythonEntry ( )
protected

Definition at line 84 of file PythonNode.cxx.

References _context, and DEBTRACE.

85 {
86  AutoGIL agil;
87  DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
88  // not Py_XDECREF of _pyfuncUnser because it is returned by PyDict_GetItem -> borrowed
89  // not Py_XDECREF of _pyfuncSer because it is returned by PyDict_GetItem -> borrowed
90  Py_XDECREF(_context);
91 }

Member Function Documentation

virtual void YACS::ENGINE::PythonEntry::assignRemotePyInterpretor ( Engines::PyNodeBase_var  remoteInterp)
protectedpure virtual
void PythonEntry::commonRemoteLoad ( InlineNode reqNode)
protected

Definition at line 289 of file PythonNode.cxx.

References commonRemoteLoadPart1(), commonRemoteLoadPart2(), and commonRemoteLoadPart3().

Referenced by YACS::ENGINE::PythonNode::loadRemote(), and YACS::ENGINE::PyFuncNode::loadRemote().

290 {
291  commonRemoteLoadPart1(reqNode);
292  bool isInitializeRequested;
293  Engines::Container_var objContainer(commonRemoteLoadPart2(reqNode,isInitializeRequested));
294  commonRemoteLoadPart3(reqNode,objContainer,isInitializeRequested);
295 }
void PythonEntry::commonRemoteLoadPart1 ( InlineNode reqNode)
protected

Definition at line 93 of file PythonNode.cxx.

References DEBTRACE, YACS::ENGINE::InlineNode::getContainer(), YACS::ENGINE::Node::getName(), YACS::ENGINE::Node::setErrorDetails(), and YACS::Exception::what().

Referenced by commonRemoteLoad().

94 {
95  DEBTRACE( "---------------PythonEntry::CommonRemoteLoad function---------------" );
96  Container *container(reqNode->getContainer());
97  bool isContAlreadyStarted(false);
98  if(container)
99  {
100  isContAlreadyStarted=container->isAlreadyStarted(reqNode);
101  if(!isContAlreadyStarted)
102  {
103  try
104  {
105  container->start(reqNode);
106  }
107  catch(Exception& e)
108  {
109  reqNode->setErrorDetails(e.what());
110  throw e;
111  }
112  }
113  }
114  else
115  {
116  std::string what("PythonEntry::CommonRemoteLoad : a load operation requested on \"");
117  what+=reqNode->getName(); what+="\" with no container specified.";
118  reqNode->setErrorDetails(what);
119  throw Exception(what);
120  }
121 }
Engines::Container_var PythonEntry::commonRemoteLoadPart2 ( InlineNode reqNode,
bool &  isInitializeRequested 
)
protected

Definition at line 123 of file PythonNode.cxx.

References assignRemotePyInterpretor(), YACS::ENGINE::SalomeContainerTmpForHP::BuildFrom(), createRemoteAdaptedPyInterpretor(), YACS::ENGINE::InlineNode::getContainer(), YACS::ENGINE::SalomeContainer::getContainerPtr(), getRemoteInterpreterHandle(), retrieveDftRemotePyInterpretorIfAny(), and YACS::ENGINE::Node::setErrorDetails().

Referenced by commonRemoteLoad(), YACS::ENGINE::PythonNode::executeRemote(), and YACS::ENGINE::PyFuncNode::executeRemote().

124 {
125  Container *container(reqNode->getContainer());
126  Engines::Container_var objContainer=Engines::Container::_nil();
127  if(!container)
128  throw Exception("No container specified !");
129  SalomeContainer *containerCast0(dynamic_cast<SalomeContainer *>(container));
130  SalomeHPContainer *containerCast1(dynamic_cast<SalomeHPContainer *>(container));
131  if(containerCast0)
132  objContainer=containerCast0->getContainerPtr(reqNode);
133  else if(containerCast1)
134  {
136  objContainer=tmpCont->getContainerPtr(reqNode);
137  }
138  else
139  throw Exception("Unrecognized type of container ! Salome one is expected for PythonNode/PyFuncNode !");
140  if(CORBA::is_nil(objContainer))
141  throw Exception("Container corba pointer is NULL for PythonNode !");
142  isInitializeRequested=false;
143  try
144  {
145  if(containerCast0)
146  {
147  createRemoteAdaptedPyInterpretor(objContainer);
148  }
149  else
150  {
151  Engines::PyNodeBase_var dftPyScript(retrieveDftRemotePyInterpretorIfAny(objContainer));
152  if(CORBA::is_nil(dftPyScript))
153  {
154  isInitializeRequested=true;
155  createRemoteAdaptedPyInterpretor(objContainer);
156  }
157  else
158  assignRemotePyInterpretor(dftPyScript);
159  }
160  }
161  catch( const SALOME::SALOME_Exception& ex )
162  {
163  std::string msg="Exception on remote python node creation ";
164  msg += '\n';
165  msg += ex.details.text.in();
166  reqNode->setErrorDetails(msg);
167  throw Exception(msg);
168  }
169  Engines::PyNodeBase_var pynode(getRemoteInterpreterHandle());
170  if(CORBA::is_nil(pynode))
171  throw Exception("In PythonNode the ref in NULL ! ");
172  return objContainer;
173 }
void PythonEntry::commonRemoteLoadPart3 ( InlineNode reqNode,
Engines::Container_ptr  objContainer,
bool  isInitializeRequested 
)
protected

Definition at line 175 of file PythonNode.cxx.

References _context, _pyfuncSer, _pyfuncSimpleSer, _pyfuncUnser, DEBTRACE, YACS::ENGINE::InlineNode::getContainer(), getRemoteInterpreterHandle(), getSerializationScript(), YACS::ENGINE::HomogeneousPoolContainer::INITIALIZE_SCRIPT_KEY, YACS::ENGINE::newPyStdOut(), SCRIPT_FOR_SIMPLE_SERIALIZATION, and YACS::ENGINE::Node::setErrorDetails().

Referenced by commonRemoteLoad().

176 {
177  Container *container(reqNode->getContainer());
178  Engines::PyNodeBase_var pynode(getRemoteInterpreterHandle());
180  {
181  AutoGIL agil;
182  const char *picklizeScript(getSerializationScript());
183  PyObject *res=PyRun_String(picklizeScript,Py_file_input,_context,_context);
184  PyObject *res2(PyRun_String(SCRIPT_FOR_SIMPLE_SERIALIZATION,Py_file_input,_context,_context));
185  if(res == NULL || res2==NULL)
186  {
187  std::string errorDetails;
188  PyObject* new_stderr = newPyStdOut(errorDetails);
189  reqNode->setErrorDetails(errorDetails);
190  PySys_SetObject((char*)"stderr", new_stderr);
191  PyErr_Print();
192  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
193  Py_DECREF(new_stderr);
194  throw Exception("Error during load");
195  }
196  Py_DECREF(res); Py_DECREF(res2);
197  _pyfuncSer=PyDict_GetItemString(_context,"pickleForDistPyth2009");
198  _pyfuncUnser=PyDict_GetItemString(_context,"unPickleForDistPyth2009");
199  _pyfuncSimpleSer=PyDict_GetItemString(_context,"pickleForVarSimplePyth2009");
200  if(_pyfuncSer == NULL)
201  {
202  std::string errorDetails;
203  PyObject *new_stderr(newPyStdOut(errorDetails));
204  reqNode->setErrorDetails(errorDetails);
205  PySys_SetObject((char*)"stderr", new_stderr);
206  PyErr_Print();
207  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
208  Py_DECREF(new_stderr);
209  throw Exception("Error during load");
210  }
211  if(_pyfuncUnser == NULL)
212  {
213  std::string errorDetails;
214  PyObject *new_stderr(newPyStdOut(errorDetails));
215  reqNode->setErrorDetails(errorDetails);
216  PySys_SetObject((char*)"stderr", new_stderr);
217  PyErr_Print();
218  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
219  Py_DECREF(new_stderr);
220  throw Exception("Error during load");
221  }
222  if(_pyfuncSimpleSer == NULL)
223  {
224  std::string errorDetails;
225  PyObject *new_stderr(newPyStdOut(errorDetails));
226  reqNode->setErrorDetails(errorDetails);
227  PySys_SetObject((char*)"stderr", new_stderr);
228  PyErr_Print();
229  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
230  Py_DECREF(new_stderr);
231  throw Exception("Error during load");
232  }
233  }
234  if(isInitializeRequested)
235  {//This one is called only once at initialization in the container if an init-script is specified.
236  try
237  {
238  std::string zeInitScriptKey(container->getProperty(HomogeneousPoolContainer::INITIALIZE_SCRIPT_KEY));
239  if(!zeInitScriptKey.empty())
240  pynode->executeAnotherPieceOfCode(zeInitScriptKey.c_str());
241  }
242  catch( const SALOME::SALOME_Exception& ex )
243  {
244  std::string msg="Exception on PythonNode::loadRemote python invocation of initializisation py script !";
245  msg += '\n';
246  msg += ex.details.text.in();
247  reqNode->setErrorDetails(msg);
248  throw Exception(msg);
249  }
250  DEBTRACE( "---------------End PyNode::loadRemote function---------------" );
251  }
252 }
virtual void YACS::ENGINE::PythonEntry::createRemoteAdaptedPyInterpretor ( Engines::Container_ptr  objContainer)
protectedpure virtual

returns an object, you have to deal with (UnRegister)

Implemented in YACS::ENGINE::PyFuncNode, and YACS::ENGINE::PythonNode.

Referenced by commonRemoteLoadPart2().

std::string PythonEntry::GetContainerLog ( const std::string &  mode,
Container container,
const Task askingTask 
)
staticprotected

Definition at line 254 of file PythonNode.cxx.

References DEBTRACE, and YACS::ENGINE::SalomeContainer::getContainerPtr().

Referenced by YACS::ENGINE::PythonNode::getContainerLog(), and YACS::ENGINE::PyFuncNode::getContainerLog().

255 {
256  if(mode=="local")
257  return "";
258 
259  std::string msg;
260  try
261  {
262  SalomeContainer *containerCast(dynamic_cast<SalomeContainer *>(container));
263  SalomeHPContainer *objContainer2(dynamic_cast<SalomeHPContainer *>(container));
264  if(containerCast)
265  {
266  Engines::Container_var objContainer(containerCast->getContainerPtr(askingTask));
267  CORBA::String_var logname = objContainer->logfilename();
268  DEBTRACE(logname);
269  msg=logname;
270  std::string::size_type pos = msg.find(":");
271  msg=msg.substr(pos+1);
272  }
273  else if(objContainer2)
274  {
275  msg="Remote PythonNode is on HP Container : no log because no info of the location by definition of HP Container !";
276  }
277  else
278  {
279  msg="Not implemented yet for container log for that type of container !";
280  }
281  }
282  catch(...)
283  {
284  msg = "Container no longer reachable";
285  }
286  return msg;
287 }
virtual Engines::PyNodeBase_var YACS::ENGINE::PythonEntry::getRemoteInterpreterHandle ( )
protectedpure virtual
virtual const char* YACS::ENGINE::PythonEntry::getSerializationScript ( ) const
protectedpure virtual
virtual Engines::PyNodeBase_var YACS::ENGINE::PythonEntry::retrieveDftRemotePyInterpretorIfAny ( Engines::Container_ptr  objContainer) const
protectedpure virtual

returns (if any) an object, you have to deal with (UnRegister)

Implemented in YACS::ENGINE::PyFuncNode, and YACS::ENGINE::PythonNode.

Referenced by commonRemoteLoadPart2().

Member Data Documentation

PyObject* YACS::ENGINE::PythonEntry::_pyfuncSer
protected
PyObject* YACS::ENGINE::PythonEntry::_pyfuncSimpleSer
protected
PyObject* YACS::ENGINE::PythonEntry::_pyfuncUnser
protected
const char PythonEntry::SCRIPT_FOR_SIMPLE_SERIALIZATION
static
Initial value:
="import cPickle\n"
"def pickleForVarSimplePyth2009(val):\n"
" return cPickle.dumps(val,-1)\n"
"\n"

Definition at line 59 of file PythonNode.hxx.

Referenced by commonRemoteLoadPart3().


The documentation for this class was generated from the following files: