Version: 9.15.0
YACS::ENGINE::DistributedPythonNode Class Reference

#include <DistributedPythonNode.hxx>

Inheritance diagram for YACS::ENGINE::DistributedPythonNode:
Collaboration diagram for YACS::ENGINE::DistributedPythonNode:

Public Member Functions

 DistributedPythonNode (const std::string &name)
 
 DistributedPythonNode (const DistributedPythonNode &other, ComposedNode *father)
 
 ~DistributedPythonNode ()
 
void execute ()
 
void load ()
 
std::string getEffectiveKindOfServer () const
 this method returns the type of container expected More...
 
std::string getKind () const
 this method returns the type of input/output expected More...
 
ServerNodecreateNode (const std::string &name) const
 
virtual std::string typeName ()
 
- Public Member Functions inherited from YACS::ENGINE::ServerNode
 ServerNode (const std::string &name)
 
 ServerNode (const ServerNode &other, ComposedNode *father)
 
void accept (Visitor *visitor)
 
bool isDeployable () const
 By definition of ServerNode class. More...
 
virtual ~ServerNode ()
 
- Public Member Functions inherited from YACS::ENGINE::InlineFuncNode
virtual void setFname (const std::string &fname)
 Set the function name to use in node execution. More...
 
virtual std::string getFname ()
 
virtual ~InlineFuncNode ()
 
virtual void checkBasicConsistency () const
 
- Public Member Functions inherited from YACS::ENGINE::InlineNode
virtual void setScript (const std::string &script)
 Set the script (as a string) to execute. More...
 
virtual std::string getScript ()
 
virtual InlineNodecloneNode (const std::string &name)
 Return a new InlineNode node by making a copy of this node. More...
 
virtual ~InlineNode ()
 
virtual void setExecutionMode (const std::string &mode)
 
virtual std::string getExecutionMode ()
 
virtual void setContainer (Container *container)
 
virtual ContainergetContainer ()
 
void performDuplicationOfPlacement (const Node &other)
 performs a duplication of placement using clone method of containers and components. clone behaviour is driven by attachOnCloning attribute. More...
 
void performShallowDuplicationOfPlacement (const Node &other)
 performs a also duplication of placement but here containers and components are not copied at all whatever the value of attachedOnCloning. More...
 
int getMaxLevelOfParallelism () const
 
- Public Member Functions inherited from YACS::ENGINE::ElementaryNode
virtual ~ElementaryNode ()
 
void exUpdateState ()
 Update the node state. More...
 
void init (bool start=true)
 
ComponentInstancegetComponent ()
 
const ComponentInstancegetComponent () const
 
YACS::StatesForNode getState () const
 
void getReadyTasks (std::vector< Task * > &tasks)
 
void edRemovePort (Port *port)
 
std::list< ElementaryNode * > getRecursiveConstituents () const
 
std::list< ProgressWeightgetProgressWeight () const
 Get the progress weight for all elementary nodes. More...
 
NodegetChildByName (const std::string &name) const
 
ComposedNodegetDynClonerIfExists (const ComposedNode *levelToStop) const
 
int getNumberOfInputPorts () const
 
int getNumberOfOutputPorts () const
 
std::string getInPortName (const InPort *) const
 
std::string getOutPortName (const OutPort *) const
 
InputPortgetInputPort (const std::string &name) const
 
OutputPortgetOutputPort (const std::string &name) const
 
std::list< InputPort * > getSetOfInputPort () const
 
std::list< OutputPort * > getSetOfOutputPort () const
 
std::list< InputPort * > getLocalInputPorts () const
 
std::list< OutputPort * > getLocalOutputPorts () const
 
std::set< OutPort * > getAllOutPortsLeavingCurrentScope () const
 
std::set< InPort * > getAllInPortsComingFromOutsideOfCurrentScope () const
 
virtual std::vector< std::pair< OutPort *, InPort * > > getSetOfLinksLeavingCurrentScope () const
 
virtual std::vector< std::pair< InPort *, OutPort * > > getSetOfLinksComingInCurrentScope () const
 
std::list< InputDataStreamPort * > getSetOfInputDataStreamPort () const
 
std::list< OutputDataStreamPort * > getSetOfOutputDataStreamPort () const
 
InputDataStreamPortgetInputDataStreamPort (const std::string &name) const
 
OutputDataStreamPortgetOutputDataStreamPort (const std::string &name) const
 
virtual InputPortcreateInputPort (const std::string &inputPortName, TypeCode *type)
 
virtual OutputPortcreateOutputPort (const std::string &outputPortName, TypeCode *type)
 
virtual InputDataStreamPortcreateInputDataStreamPort (const std::string &inputPortDSName, TypeCode *type)
 
virtual OutputDataStreamPortcreateOutputDataStreamPort (const std::string &outputPortDSName, TypeCode *type)
 
virtual InputPortedAddInputPort (const std::string &inputPortName, TypeCode *type)
 
virtual OutputPortedAddOutputPort (const std::string &outputPortName, TypeCode *type)
 
virtual InputDataStreamPortedAddInputDataStreamPort (const std::string &inputPortDSName, TypeCode *type)
 
virtual OutputDataStreamPortedAddOutputDataStreamPort (const std::string &outputPortDSName, TypeCode *type)
 
virtual void edOrderInputPorts (const std::list< InputPort * > &ports)
 
virtual void edOrderOutputPorts (const std::list< OutputPort * > &ports)
 
virtual void edUpdateState ()
 update the status of the node More...
 
virtual void ensureLoading ()
 Put this node into TOLOAD state when possible. More...
 
ComplexWeightgetWeight ()
 
void setWeight (double elementaryWeight)
 
void getWeightRegardingDPL (ComplexWeight *weight)
 
void partitionRegardingDPL (const PartDefinition *pd, std::map< ComposedNode *, YACS::BASES::AutoRefCnt< PartDefinition > > &zeMap)
 
void begin ()
 
bool isReady ()
 
void finished ()
 
void aborted ()
 
void loaded ()
 Notify this node that it is loaded. More...
 
void connected ()
 Notify this node that it is connected. More...
 
virtual std::string getErrorDetails ()
 Give a description of error when node status is ERROR. More...
 
virtual void initService ()
 
virtual void connectService ()
 
virtual void disconnectService ()
 
virtual void getCoupledTasks (std::set< Task * > &coupledSet)
 Calls getCoupledNodes for Task interface. More...
 
virtual void getCoupledNodes (std::set< Task * > &coupledSet)
 Put all nodes that are coupled to this node in coupledSet. More...
 
virtual void addDatastreamPortToInitMultiService (const std::string &port_name, int number)
 
- Public Member Functions inherited from YACS::ENGINE::Node
virtual ~Node ()
 
virtual void shutdown (int level)
 Stop all pending activities of the node. More...
 
virtual void resetState (int level)
 Reset the node state depending on the parameter level. More...
 
Nodeclone (ComposedNode *father, bool editionOnly=true) const
 This method MUST NEVER BE VIRTUAL More...
 
NodecloneWithoutCompAndContDeepCpy (ComposedNode *father, bool editionOnly=true) const
 This method MUST NEVER BE VIRTUAL More...
 
void setState (YACS::StatesForNode theState)
 Sets the given state for node. More...
 
virtual YACS::StatesForNode getEffectiveState () const
 Return the node state in the context of its father. More...
 
virtual YACS::StatesForNode getEffectiveState (const Node *) const
 Return the effective state of a node in the context of this one (its father) More...
 
std::string getColorState (YACS::StatesForNode state) const
 Return the color associated to a state. More...
 
InGategetInGate ()
 
OutGategetOutGate ()
 
const std::string & getName () const
 
void setName (const std::string &name)
 Change the name of the node. More...
 
ComposedNodegetFather () const
 
const std::string getId () const
 
bool exIsControlReady () const
 
std::list< Node * > getOutNodes () const
 
virtual void writeDot (std::ostream &os) const
 Dump to the input stream a dot representation of the node. More...
 
void writeDotInFile (const std::string &fileName) const
 
virtual void exFailedState ()
 Notify this node that its execution has failed. More...
 
virtual void exDisabledState ()
 Notify this node that it has been disabled. More...
 
std::list< InPort * > getSetOfInPort () const
 
std::list< OutPort * > getSetOfOutPort () const
 
virtual std::set< InputPort * > edGetSetOfUnitializedInputPort () const
 Becomes deprecated soon. Replaced by ComposedNode::CheckConsistency. More...
 
virtual bool edAreAllInputPortInitialized () const
 Becomes deprecated soon. Replaced by ComposedNode::CheckConsistency. More...
 
InPortgetInPort (const std::string &name) const
 
InPropertyPortgetInPropertyPort () const
 
virtual OutPortgetOutPort (const std::string &name) const
 
std::list< ComposedNode * > getAllAscendanceOf (ComposedNode *levelToStop=0) const
 
bool operator> (const Node &other) const
 
bool operator< (const Node &other) const
 
std::string getImplementation () const
 
DynParaLoopgetClosestDPLAmongAncestors () const
 
virtual ComposedNodegetRootNode () const
 
virtual void setProperty (const std::string &name, const std::string &value)
 
virtual std::string getProperty (const std::string &name)
 
std::map< std::string, std::string > getProperties ()
 
std::map< std::string, std::string > getPropertyMap ()
 
virtual void setProperties (std::map< std::string, std::string > properties)
 
virtual ProcgetProc ()
 
virtual const ProcgetProc () const
 
std::string getQualifiedName () const
 same as Node::getName() in most cases, but differs for children of switch More...
 
int getNumId ()
 return node instance identifiant, unique for each node instance More...
 
std::vector< std::pair< std::string, int > > getDPLScopeInfo (ComposedNode *gfn)
 
virtual void applyDPLScope (ComposedNode *gfn)
 
virtual void sendEvent (const std::string &event)
 emit notification to all observers registered with the dispatcher More...
 
virtual void sendEvent2 (const std::string &event, void *something)
 emit notification to all observers registered with the dispatcher More...
 
virtual std::string getErrorDetails () const
 
virtual void setErrorDetails (const std::string &error)
 
virtual void modified ()
 Sets Node in modified state and its father if it exists. More...
 
virtual int isModified ()
 
virtual int isValid ()
 indicates if the node is valid (returns 1) or not (returns 0) More...
 
virtual std::string getErrorReport ()
 returns a string that contains an error report if the node is in error More...
 
virtual std::string getContainerLog ()
 returns a string that contains the name of the container log file if it exists More...
 
virtual void cleanNodes ()
 Clean the node in case of not clean exit. More...
 
- Public Member Functions inherited from YACS::ENGINE::Task
virtual void imposeResource (const std::string &resource_name, const std::string &container_name)
 
virtual bool canAcceptImposedResource ()
 
virtual bool hasImposedResource () const
 
virtual ~Task ()
 

Static Public Attributes

static const char KIND [] ="DistPython"
 
static const char IMPL_NAME [] ="Python"
 
static const char SALOME_CONTAINER_METHOD_IDL [] ="createPyNode"
 
- Static Public Attributes inherited from YACS::ENGINE::InlineNode
static const char LOCAL_STR [] ="local"
 
static const char REMOTE_STR [] ="remote"
 
- Static Public Attributes inherited from YACS::ENGINE::Node
static std::map< int, Node * > idMap
 

Protected Member Functions

NodesimpleClone (ComposedNode *father, bool editionOnly) const
 
- Protected Member Functions inherited from YACS::ENGINE::InlineFuncNode
 InlineFuncNode (const InlineFuncNode &other, ComposedNode *father)
 
 InlineFuncNode (const std::string &name)
 
- Protected Member Functions inherited from YACS::ENGINE::InlineNode
 InlineNode (const InlineNode &other, ComposedNode *father)
 
 InlineNode (const std::string &name)
 
- Protected Member Functions inherited from YACS::ENGINE::ElementaryNode
 ElementaryNode (const std::string &name)
 
 ElementaryNode (const ElementaryNode &other, ComposedNode *father)
 
void initCommonPartWithoutStateManagement (bool start)
 
virtual void createMultiDatastreamPorts ()
 
void edDisconnectAllLinksWithMe ()
 
bool areAllInputPortsValid () const
 
template<class PORT >
PORT * getPort (const std::string &name, const std::list< PORT * > &setOfPorts) const
 
template<class PORT , class ENUMTYPE >
PORT * edAddPort (const std::string &portName, std::list< PORT * > &setOfPorts, ENUMTYPE type)
 
template<class PORT , class ENUMTYPE >
bool edCheckAddPort (const std::string &portName, std::list< PORT * > &setOfPorts, ENUMTYPE type)
 
- Protected Member Functions inherited from YACS::ENGINE::Node
 Node (const std::string &name)
 
 Node (const Node &other, ComposedNode *father)
 
virtual void exForwardFailed ()
 
virtual void exForwardFinished ()
 

Protected Attributes

PyObject * _context
 
PyObject * _pyfuncSer
 
PyObject * _pyfuncUnser
 
Engines::PyNode_var _pynode
 
- Protected Attributes inherited from YACS::ENGINE::InlineFuncNode
std::string _fname
 
- Protected Attributes inherited from YACS::ENGINE::InlineNode
std::string _script
 
std::string _mode
 
Container_container
 
- Protected Attributes inherited from YACS::ENGINE::ElementaryNode
std::list< InputPort * > _setOfInputPort
 
std::list< OutputPort * > _setOfOutputPort
 
std::list< InputDataStreamPort * > _setOfInputDataStreamPort
 
std::list< OutputDataStreamPort * > _setOfOutputDataStreamPort
 
ComplexWeight _weight
 
bool _createDatastreamPorts
 
bool _multi_port_node
 
- Protected Attributes inherited from YACS::ENGINE::Node
InGate _inGate
 
OutGate _outGate
 
InPropertyPort_inPropertyPort
 
std::string _name
 
ComposedNode_father
 
YACS::StatesForNode _state
 
int _modified
 
std::string _errorDetails
 
int _numId
 
std::string _implementation
 
std::map< std::string, std::string > _propertyMap
 
Node_eventReceiver =nullptr
 

Private Member Functions

void initMySelf ()
 
void dealException (CORBA::Exception *exc, const char *method, const char *ref)
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::ENGINE::Node
static std::string getStateName (YACS::StatesForNode state)
 Return the name of a state. More...
 
static void checkValidityOfNodeName (const std::string &name)
 
- Public Attributes inherited from YACS::ENGINE::Node
YACS::Colour _colour
 
- Static Protected Member Functions inherited from YACS::ENGINE::ElementaryNode
template<class PORT >
static void edRemovePortTypedFromSet (PORT *port, std::list< PORT * > &setOfPorts)
 
template<class PORT >
static bool isPortNameAlreadyExist (const std::string &portName, const std::list< PORT * > &setOfPorts)
 
- Static Protected Member Functions inherited from YACS::ENGINE::Node
static void checkValidityOfPortName (const std::string &name)
 
static ComposedNodecheckHavingCommonFather (Node *node1, Node *node2)
 
- Static Protected Attributes inherited from YACS::ENGINE::Node
static const char SEP_CHAR_IN_PORT [] ="."
 
static int _total = 0
 

Detailed Description

Definition at line 44 of file DistributedPythonNode.hxx.

Constructor & Destructor Documentation

◆ DistributedPythonNode() [1/2]

DistributedPythonNode::DistributedPythonNode ( const std::string &  name)

◆ DistributedPythonNode() [2/2]

DistributedPythonNode::DistributedPythonNode ( const DistributedPythonNode other,
ComposedNode father 
)

Definition at line 49 of file DistributedPythonNode.cxx.

49  :ServerNode(other,father),_context(0),_pyfuncSer(0),_pyfuncUnser(0)
50 {
51  initMySelf();
52 }

References initMySelf().

◆ ~DistributedPythonNode()

DistributedPythonNode::~DistributedPythonNode ( )

Definition at line 54 of file DistributedPythonNode.cxx.

55 {
56  AutoGIL agil;
57  Py_DECREF(_context);
58 }

References _context.

Member Function Documentation

◆ createNode()

ServerNode * DistributedPythonNode::createNode ( const std::string &  name) const
virtual

Implements YACS::ENGINE::ServerNode.

Definition at line 281 of file DistributedPythonNode.cxx.

282 {
283  ServerNode *ret=new DistributedPythonNode(name);
284  ret->setContainer(_container);
285  return ret;
286 }
DistributedPythonNode(const std::string &name)
virtual void setContainer(Container *container)
Definition: InlineNode.cxx:105

References YACS::ENGINE::InlineNode::_container, DistributedPythonNode(), and YACS::ENGINE::InlineNode::setContainer().

◆ dealException()

void DistributedPythonNode::dealException ( CORBA::Exception *  exc,
const char *  method,
const char *  ref 
)
private

Definition at line 295 of file DistributedPythonNode.cxx.

296 {
297  if( exc )
298  {
299  GURU_YACSTRACE( "An exception was thrown!" );
300  GURU_YACSTRACE( "The raised exception is of Type:" << exc->_name() );
301 
302  CORBA::SystemException* sysexc;
303  sysexc=CORBA::SystemException::_downcast(exc);
304  if(sysexc != NULL)
305  {
306  // It's a SystemException
307  GURU_YACSTRACE( "minor code: " << sysexc->minor() );
308  GURU_YACSTRACE( "completion code: " << sysexc->completed() );
309  std::string text="Execution problem: ";
310  std::string excname=sysexc->_name();
311  if(excname == "BAD_OPERATION")
312  {
313  text=text+"bad operation detected";
314  }
315  else if(excname == "MARSHAL" && sysexc->minor() == omni::MARSHAL_PassEndOfMessage)
316  {
317  text=text+"probably an error in arguments of service '" + method + "' from component '" +ref+ "'";
318  }
319  else if(excname == "COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_UnMarshalResults)
320  {
321  text=text+"probably an error in output arguments of service '" + method + "' from component '" +ref+ "'";
322  }
323  else if(excname == "COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_UnMarshalArguments)
324  {
325  text=text+"probably an error in input arguments of service '" + method + "' from component '" +ref+ "'";
326  }
327  else if(excname == "COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_WaitingForReply)
328  {
329  text=text+"probably an error in input arguments of service '" + method + "' from component '" +ref+ "'";
330  }
331  else
332  {
333  GURU_YACSTRACE(sysexc->NP_minorString() );
334  text=text+"System Exception "+ excname;
335  }
336  _errorDetails=text;
337  throw Exception(text);
338  }
339 
340  // Not a System Exception
341  CORBA::UnknownUserException* userexc;
342  userexc=CORBA::UnknownUserException::_downcast(exc);
343  if(userexc != NULL)
344  {
345  CORBA::Any anyExcept = userexc->exception();
346 
347  const SALOME::SALOME_Exception* salexc;
348  if(anyExcept >>= salexc)
349  {
350  GURU_YACSTRACE("SALOME_Exception: "<< salexc->details.sourceFile);
351  GURU_YACSTRACE("SALOME_Exception: "<<salexc->details.lineNumber);
352  _errorDetails=salexc->details.text;
353  throw Exception("Execution problem: Salome Exception occurred" + getErrorDetails() );
354  }
355  std::string msg="Execution problem: User Exception occurred";
356  _errorDetails=msg;
357  throw Exception(msg);
358  }
359  std::string msg="Execution problem";
360  _errorDetails=msg;
361  throw Exception(msg);
362  }
363 }
#define GURU_YACSTRACE(msg)
Definition: YacsTrace.hxx:55
virtual std::string getErrorDetails()
Give a description of error when node status is ERROR.
std::string _errorDetails
Definition: Node.hxx:93
def ref(target, callback=None)
Definition: CONNECTOR.py:120

References YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::ElementaryNode::getErrorDetails(), GURU_YACSTRACE, and gui.CONNECTOR::ref().

◆ execute()

void DistributedPythonNode::execute ( )
virtual

Implements YACS::ENGINE::Task.

Definition at line 161 of file DistributedPythonNode.cxx.

162 {
163  GURU_YACSTRACE("+++++++++++++++++ DistributedPythonNode::execute: " << getName() << " " << getFname() << " +++++++++++++++++" );
165  PyObject* ob;
166  if(!_pyfuncSer)
167  throw Exception("DistributedPythonNode badly loaded");
168  Engines::pickledArgs *serializationInputCorba(0);
169  PyObject *args(0);
170  {
171  AutoGIL agil;
172 
173  GURU_YACSTRACE( "---------------DistributedPythonNode::inputs---------------" );
174  args = PyTuple_New(getNumberOfInputPorts()) ;
175  int pos=0;
176  for(list<InputPort *>::iterator iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++,pos++)
177  {
178  InputPyPort *p=(InputPyPort *)*iter2;
179  ob=p->getPyObj();
180  Py_INCREF(ob);
181  PyTuple_SetItem(args,pos,ob);
182  }
183  PyObject *serializationInput=PyObject_CallObject(_pyfuncSer,args);
184  Py_ssize_t len = PyBytes_Size(serializationInput);
185  char* serializationInputC = PyBytes_AsString(serializationInput);
186  //int ret = PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len);
187  serializationInputCorba=new Engines::pickledArgs;
188  serializationInputCorba->length(len+1);
189  for(int i=0;i<len+1;i++)
190  (*serializationInputCorba)[i]=serializationInputC[i];
191  Py_DECREF(serializationInput);
192  }
193  //serializationInputCorba[serializationInputC.length()]='\0';
194  DEBUG_YACSTRACE( "-----------------DistributedPythonNode starting remote python invocation-----------------" );
195  Engines::pickledArgs *resultCorba;
196  try
197  {
198  resultCorba=_pynode->execute(getFname().c_str(),*serializationInputCorba);
199  }
200  catch(...)
201  {
202  std::string msg="Exception on remote python invocation";
203  _errorDetails=msg;
204  throw Exception(msg);
205  }
206  DEBUG_YACSTRACE( "-----------------DistributedPythonNode end of remote python invocation-----------------" );
207  //
208  delete serializationInputCorba;
209  char *resultCorbaC=new char[resultCorba->length()+1];
210  resultCorbaC[resultCorba->length()]='\0';
211  for(int i=0;i<resultCorba->length();i++)
212  resultCorbaC[i]=(*resultCorba)[i];
213  int lenResCorba=resultCorba->length();
214  delete resultCorba;
215  {
216  AutoGIL agil;
217  args = PyTuple_New(1);
218  //PyObject* resultPython=PyBytes_FromString(resultCorbaC);
219  PyObject* resultPython=PyBytes_FromStringAndSize(resultCorbaC,lenResCorba);
220  delete [] resultCorbaC;
221  PyTuple_SetItem(args,0,resultPython);
222  PyObject *finalResult=PyObject_CallObject(_pyfuncUnser,args);
223  GURU_YACSTRACE( "-----------------DistributedPythonNode::outputs-----------------" );
224  if(finalResult == NULL)
225  {
226  std::stringstream msg;
227  msg << "Conversion with pickle of output ports failed !";
228  msg << " : " << __FILE__ << ":" << __LINE__;
229  _errorDetails=msg.str();
230  throw YACS::ENGINE::ConversionException(msg.str());
231  }
232  int nres=1;
233  if(finalResult == Py_None)
234  nres=0;
235  else if(PyTuple_Check(finalResult))
236  nres=PyTuple_Size(finalResult);
237 
238  if(getNumberOfOutputPorts() != nres)
239  {
240  std::string msg="Number of output arguments : Mismatch between definition and execution";
241  Py_DECREF(finalResult);
242  _errorDetails=msg;
243  throw Exception(msg);
244  }
245  try
246  {
247  int pos(0);
248  for(list<OutputPort *>::iterator iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++, pos++)
249  {
250  OutputPyPort *p=(OutputPyPort *)*iter;
251  GURU_YACSTRACE( "port name: " << p->getName() );
252  GURU_YACSTRACE( "port kind: " << p->typeName() );
253  GURU_YACSTRACE( "port pos : " << pos );
254  if(PyTuple_Check(finalResult))ob=PyTuple_GetItem(finalResult,pos) ;
255  else ob=finalResult;
256  GURU_YACSTRACE( "ob refcnt: " << ob->ob_refcnt );
257  p->put(ob);
258  }
259  }
260  catch(ConversionException& ex)
261  {
262  Py_DECREF(finalResult);
263  _errorDetails=ex.what();
264  throw;
265  }
266  }
267  GURU_YACSTRACE( "++++++++++++++ End DistributedPythonNode::execute: " << getName() << " ++++++++++++++++++++" );
268 }
int Py_ssize_t
Definition: PythonNode.cxx:45
#define DEBUG_YACSTRACE(msg)
Definition: YacsTrace.hxx:53
std::string getName() const
std::list< InputPort * > _setOfInputPort
std::list< OutputPort * > _setOfOutputPort
virtual std::string getFname()
Definition: InlineNode.hxx:101
Class for Python Ports.
Definition: PythonPorts.hxx:74
const std::string & getName() const
Definition: Node.hxx:125
virtual std::string typeName()
Definition: Proc.hxx:84
Proc * p
Definition: driver.cxx:216

References YACS::ENGINE::Node::_errorDetails, _pyfuncSer, _pyfuncUnser, _pynode, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, driver_internal::args, DEBUG_YACSTRACE, testCppPluginInvokation::ex, YACS::ENGINE::InlineFuncNode::getFname(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::ElementaryNode::getNumberOfInputPorts(), YACS::ENGINE::ElementaryNode::getNumberOfOutputPorts(), GURU_YACSTRACE, yacsorb.CORBAEngineTest::i, p, and YACS::ENGINE::Proc::typeName().

◆ getEffectiveKindOfServer()

std::string DistributedPythonNode::getEffectiveKindOfServer ( ) const
virtual

this method returns the type of container expected

Implements YACS::ENGINE::ServerNode.

Definition at line 270 of file DistributedPythonNode.cxx.

271 {
272  return "Salome";
273 }

◆ getKind()

std::string DistributedPythonNode::getKind ( ) const

this method returns the type of input/output expected

not a bug : this is to use classical python port translators.

Definition at line 275 of file DistributedPythonNode.cxx.

276 {
278  return PythonNode::KIND;
279 }
static const char KIND[]
Definition: PythonNode.hxx:122

References YACS::ENGINE::PythonNode::KIND.

◆ initMySelf()

void DistributedPythonNode::initMySelf ( )
private

Definition at line 288 of file DistributedPythonNode.cxx.

289 {
291  AutoGIL agil;
292  _context=PyDict_New();
293 }
std::string _implementation
Definition: Node.hxx:97

References _context, YACS::ENGINE::Node::_implementation, and IMPL_NAME.

Referenced by DistributedPythonNode().

◆ load()

void DistributedPythonNode::load ( )
virtual

Reimplemented from YACS::ENGINE::ServerNode.

Definition at line 60 of file DistributedPythonNode.cxx.

61 {
62  bool isContAlreadyStarted(false);
63  if(_container)
64  isContAlreadyStarted=_container->isAlreadyStarted(this);
66  {
67  AutoGIL agil;
68  if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
69  {
70  stringstream msg;
71  msg << "Impossible to set builtins" << __FILE__ << ":" << __LINE__;
72  _errorDetails=msg.str();
73  throw Exception(msg.str());
74  }
75  const char picklizeScript[]="import pickle\ndef pickleForDistPyth2009(*args,**kws):\n return pickle.dumps((args,kws),-1)\n\ndef unPickleForDistPyth2009(st):\n args=pickle.loads(st)\n return args\n";
76  PyObject *res=PyRun_String(picklizeScript,Py_file_input,_context,_context);
77  if(res == NULL)
78  {
79  _errorDetails="";
80  PyObject* new_stderr = newPyStdOut(_errorDetails);
81  PySys_SetObject((char*)"stderr", new_stderr);
82  PyErr_Print();
83  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
84  Py_DECREF(new_stderr);
85  throw Exception("Error during execution");
86  return;
87  }
88  Py_DECREF(res);
89  _pyfuncSer=PyDict_GetItemString(_context,"pickleForDistPyth2009");
90  _pyfuncUnser=PyDict_GetItemString(_context,"unPickleForDistPyth2009");
91  if(_pyfuncSer == NULL)
92  {
93  _errorDetails="";
94  PyObject* new_stderr = newPyStdOut(_errorDetails);
95  PySys_SetObject((char*)"stderr", new_stderr);
96  PyErr_Print();
97  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
98  Py_DECREF(new_stderr);
99  throw Exception("Error during execution");
100  }
101  if(_pyfuncUnser == NULL)
102  {
103  _errorDetails="";
104  PyObject* new_stderr = newPyStdOut(_errorDetails);
105  PySys_SetObject((char*)"stderr", new_stderr);
106  PyErr_Print();
107  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
108  Py_DECREF(new_stderr);
109  throw Exception("Error during execution");
110  }
111 
112  Engines::Container_var objContainer=Engines::Container::_nil();
113  if(!_container)
114  throw Exception("No container specified !");
115  SalomeContainer *containerCast0(dynamic_cast<SalomeContainer *>(_container));
116  SalomeHPContainer *containerCast1(dynamic_cast<SalomeHPContainer *>(_container));
117  if(containerCast0)
118  objContainer=containerCast0->getContainerPtr(this);
119  else if(containerCast1)
120  {
122  objContainer=tmpCont->getContainerPtr(this);
123  }
124  else
125  throw Exception("Unrecognized type of container ! Salome one is expected !");
126  if(CORBA::is_nil(objContainer))
127  throw Exception("Container corba pointer is NULL !");
128 
129  try
130  {
131  if(containerCast0 || !isContAlreadyStarted)
132  {
133  _pynode = objContainer->createPyNode(getName().c_str(),getScript().c_str());
134  }
135  else
136  {
137  Engines::PyNode_var dftPyScript(objContainer->getDefaultPyNode(getName().c_str()));
138  if(CORBA::is_nil(dftPyScript))
139  _pynode = objContainer->createPyNode(getName().c_str(),getScript().c_str());
140  else
141  _pynode = dftPyScript;
142  }
143  }
144  catch( const SALOME::SALOME_Exception& ex )
145  {
146  std::string msg="Exception on remote python node creation ";
147  msg += '\n';
148  msg += ex.details.text.in();
149  _errorDetails=msg;
150  throw Exception(msg);
151  }
152 
153  if(CORBA::is_nil(_pynode))
154  throw Exception("In DistributedPythonNode the ref in NULL ! ");
155 
156 
157  DEBUG_YACSTRACE( "---------------End PyfuncSerNode::load function---------------" );
158  }
159 }
virtual bool isAlreadyStarted(const Task *askingNode) const =0
virtual std::string getScript()
Definition: InlineNode.hxx:51
static SalomeContainerTmpForHP * BuildFrom(const SalomeHPContainer *cont, const Task *askingNode)
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()
PyObject * newPyStdOut(std::string &out)
Definition: PyStdout.cxx:129

References YACS::ENGINE::InlineNode::_container, _context, YACS::ENGINE::Node::_errorDetails, _pyfuncSer, _pyfuncUnser, _pynode, YACS::ENGINE::SalomeContainerTmpForHP::BuildFrom(), DEBUG_YACSTRACE, testCppPluginInvokation::ex, YACS::ENGINE::SalomeContainer::getContainerPtr(), YACS::ENGINE::Node::getName(), YACS::ENGINE::getSALOMERuntime(), YACS::ENGINE::InlineNode::getScript(), YACS::ENGINE::Container::isAlreadyStarted(), YACS::ENGINE::ServerNode::load(), and YACS::ENGINE::newPyStdOut().

◆ simpleClone()

Node * DistributedPythonNode::simpleClone ( ComposedNode father,
bool  editionOnly 
) const
protectedvirtual

Implements YACS::ENGINE::Node.

Definition at line 39 of file DistributedPythonNode.cxx.

40 {
41  return new DistributedPythonNode(*this,father);
42 }

◆ typeName()

virtual std::string YACS::ENGINE::DistributedPythonNode::typeName ( )
inlinevirtual

Reimplemented from YACS::ENGINE::ServerNode.

Definition at line 59 of file DistributedPythonNode.hxx.

59 {return "YACS__ENGINE__DistributedPythonNode";}

Member Data Documentation

◆ _context

PyObject* YACS::ENGINE::DistributedPythonNode::_context
protected

Definition at line 68 of file DistributedPythonNode.hxx.

Referenced by initMySelf(), load(), and ~DistributedPythonNode().

◆ _pyfuncSer

PyObject* YACS::ENGINE::DistributedPythonNode::_pyfuncSer
protected

Definition at line 69 of file DistributedPythonNode.hxx.

Referenced by execute(), and load().

◆ _pyfuncUnser

PyObject* YACS::ENGINE::DistributedPythonNode::_pyfuncUnser
protected

Definition at line 70 of file DistributedPythonNode.hxx.

Referenced by execute(), and load().

◆ _pynode

Engines::PyNode_var YACS::ENGINE::DistributedPythonNode::_pynode
protected

Definition at line 71 of file DistributedPythonNode.hxx.

Referenced by execute(), and load().

◆ IMPL_NAME

const char DistributedPythonNode::IMPL_NAME ="Python"
static

Definition at line 65 of file DistributedPythonNode.hxx.

Referenced by initMySelf().

◆ KIND

const char DistributedPythonNode::KIND ="DistPython"
static

Definition at line 64 of file DistributedPythonNode.hxx.

◆ SALOME_CONTAINER_METHOD_IDL

const char DistributedPythonNode::SALOME_CONTAINER_METHOD_IDL ="createPyNode"
static

Definition at line 66 of file DistributedPythonNode.hxx.


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