Version: 8.3.0
YACS::ENGINE::PythonNode Class Reference

#include <PythonNode.hxx>

Inheritance diagram for YACS::ENGINE::PythonNode:
Collaboration diagram for YACS::ENGINE::PythonNode:

Public Member Functions

 PythonNode (const PythonNode &other, ComposedNode *father)
 
 PythonNode (const std::string &name)
 
virtual ~PythonNode ()
 
virtual void checkBasicConsistency () const throw (Exception)
 
virtual void execute ()
 
virtual void load ()
 
virtual void loadRemote ()
 
virtual void loadLocal ()
 
virtual void executeRemote ()
 
virtual void executeLocal ()
 
virtual void shutdown (int level)
 Stop all pending activities of the node. More...
 
std::string getContainerLog ()
 returns a string that contains the name of the container log file if it exists More...
 
PythonNodecloneNode (const std::string &name)
 Create a new node of same type with a given name. More...
 
virtual std::string typeName ()
 
void applyDPLScope (ComposedNode *gfn)
 
- 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 void accept (Visitor *visitor)
 
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...
 
bool isDeployable () const
 
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) throw (Exception)
 
std::list< ElementaryNode * > getRecursiveConstituents () const
 
std::list< ProgressWeightgetProgressWeight () const
 Get the progress weight for all elementary nodes. More...
 
NodegetChildByName (const std::string &name) const throw (Exception)
 
ComposedNodegetDynClonerIfExists (const ComposedNode *levelToStop) const
 
int getNumberOfInputPorts () const
 
int getNumberOfOutputPorts () const
 
std::string getInPortName (const InPort *) const throw (Exception)
 
std::string getOutPortName (const OutPort *) const throw (Exception)
 
InputPortgetInputPort (const std::string &name) const throw (Exception)
 
OutputPortgetOutputPort (const std::string &name) const throw (Exception)
 
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 throw (Exception)
 
OutputDataStreamPortgetOutputDataStreamPort (const std::string &name) const throw (Exception)
 
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) throw (Exception)
 
virtual OutputPortedAddOutputPort (const std::string &outputPortName, TypeCode *type) throw (Exception)
 
virtual InputDataStreamPortedAddInputDataStreamPort (const std::string &inputPortDSName, TypeCode *type) throw (Exception)
 
virtual OutputDataStreamPortedAddOutputDataStreamPort (const std::string &outputPortDSName, TypeCode *type) throw (Exception)
 
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...
 
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)
 
template<class PORT >
void edRemovePortTypedFromSet (PORT *port, std::list< PORT * > &setOfPorts) throw (Exception)
 
template<class PORT >
bool isPortNameAlreadyExist (const std::string &portName, const std::list< PORT * > &setOfPorts)
 
- Public Member Functions inherited from YACS::ENGINE::Node
virtual ~Node ()
 
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...
 
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 throw (Exception)
 
InPropertyPortgetInPropertyPort () const throw (Exception)
 
virtual OutPortgetOutPort (const std::string &name) const throw (Exception)
 
std::list< ComposedNode * > getAllAscendanceOf (ComposedNode *levelToStop=0) const
 
bool operator> (const Node &other) const
 
bool operator< (const Node &other) const
 
std::string getImplementation () const
 
virtual ComposedNodegetRootNode () const throw (Exception)
 
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 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 void cleanNodes ()
 Clean the node in case of not clean exit. More...
 
- Public Member Functions inherited from YACS::ENGINE::Task
virtual ~Task ()
 

Static Public Attributes

static const char KIND [] ="Python"
 
static const char IMPL_NAME [] ="Python"
 
static const char SCRIPT_FOR_SERIALIZATION []
 
static const char REMOTE_NAME [] ="remote"
 
static const char DPL_INFO_NAME [] ="my_dpl_localization"
 
- 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::PythonEntry
static const char SCRIPT_FOR_SIMPLE_SERIALIZATION []
 

Protected Member Functions

NodesimpleClone (ComposedNode *father, bool editionOnly) const
 
void createRemoteAdaptedPyInterpretor (Engines::Container_ptr objContainer)
 returns an object, you have to deal with (UnRegister) More...
 
Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny (Engines::Container_ptr objContainer) const
 returns (if any) an object, you have to deal with (UnRegister) More...
 
void assignRemotePyInterpretor (Engines::PyNodeBase_var remoteInterp)
 
Engines::PyNodeBase_var getRemoteInterpreterHandle ()
 
const char * getSerializationScript () const
 
- 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 throw (Exception)
 
template<class PORT , class ENUMTYPE >
PORT * edAddPort (const std::string &portName, std::list< PORT * > &setOfPorts, ENUMTYPE type) throw (Exception)
 
template<class PORT , class ENUMTYPE >
bool edCheckAddPort (const std::string &portName, std::list< PORT * > &setOfPorts, ENUMTYPE type) throw (Exception)
 
- 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 Member Functions inherited from YACS::ENGINE::PythonEntry
 PythonEntry ()
 
 ~PythonEntry ()
 
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)
 

Protected Attributes

Engines::PyScriptNode_var _pynode
 
- 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
 
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
 
- Protected Attributes inherited from YACS::ENGINE::PythonEntry
PyObject * _context
 
PyObject * _pyfuncSer
 
PyObject * _pyfuncUnser
 
PyObject * _pyfuncSimpleSer
 

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...
 
- 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) throw (Exception)
 
template<class PORT >
static bool isPortNameAlreadyExist (const std::string &portName, const std::list< PORT * > &setOfPorts)
 
- Static Protected Member Functions inherited from YACS::ENGINE::PythonEntry
static std::string GetContainerLog (const std::string &mode, Container *container, const Task *askingTask)
 
- Static Protected Attributes inherited from YACS::ENGINE::Node
static const char SEP_CHAR_IN_PORT [] ="."
 
static int _total = 0
 

Detailed Description

Definition at line 62 of file PythonNode.hxx.

Constructor & Destructor Documentation

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

Definition at line 297 of file PythonNode.cxx.

References YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::Node::_implementation, YACS::ENGINE::getSALOMERuntime(), and IMPL_NAME.

Referenced by cloneNode(), and simpleClone().

297  :InlineNode(other,father)
298 {
300  {
301  AutoGIL agil;
302  _context=PyDict_New();
303  if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
304  {
305  stringstream msg;
306  msg << "Impossible to set builtins" << __FILE__ << ":" << __LINE__;
307  _errorDetails=msg.str();
308  throw Exception(msg.str());
309  }
310  }
311 }
PythonNode::PythonNode ( const std::string &  name)

Definition at line 313 of file PythonNode.cxx.

References YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::Node::_implementation, YACS::ENGINE::getSALOMERuntime(), and IMPL_NAME.

313  :InlineNode(name)
314 {
316  {
317  AutoGIL agil;
318  _context=PyDict_New();
319  if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
320  {
321  stringstream msg;
322  msg << "Impossible to set builtins" << __FILE__ << ":" << __LINE__;
323  _errorDetails=msg.str();
324  throw Exception(msg.str());
325  }
326  }
327 }
PythonNode::~PythonNode ( )
virtual

Definition at line 329 of file PythonNode.cxx.

References _pynode.

330 {
331  if(!CORBA::is_nil(_pynode))
332  {
333  _pynode->UnRegister();
334  }
335 }

Member Function Documentation

void PythonNode::applyDPLScope ( ComposedNode gfn)
virtual

Method called by the Executor only if the executor is sensitive of scope of DynParaLoop. This method is virtual and empty because by default nothing is done.

Reimplemented from YACS::ENGINE::Node.

Definition at line 725 of file PythonNode.cxx.

References YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::InlineNode::_mode, YACS::ENGINE::PythonEntry::_pyfuncSimpleSer, _pynode, DPL_INFO_NAME, YACS::ENGINE::Node::getDPLScopeInfo(), CORBAEngineTest::i, p, REMOTE_NAME, and PMMLBasicsTestLauncher::ret.

726 {
727  std::vector< std::pair<std::string,int> > ret(getDPLScopeInfo(gfn));
728  if(ret.empty())
729  return ;
730  //
731  PyObject *ob(0);
732  {
733  AutoGIL agil;
734  std::size_t sz(ret.size());
735  ob=PyList_New(sz);
736  for(std::size_t i=0;i<sz;i++)
737  {
738  const std::pair<std::string,int>& p(ret[i]);
739  PyObject *elt(PyTuple_New(2));
740  PyTuple_SetItem(elt,0,PyString_FromString(p.first.c_str()));
741  PyTuple_SetItem(elt,1,PyLong_FromLong(p.second));
742  PyList_SetItem(ob,i,elt);
743  }
744  }
745  if(_mode==REMOTE_NAME)
746  {
747  Engines::pickledArgs_var serializationInputCorba(new Engines::pickledArgs);
748  {
749  AutoGIL agil;
750  PyObject *serializationInput(PyObject_CallFunctionObjArgs(_pyfuncSimpleSer,ob,NULL));
751  Py_XDECREF(ob);
752  char *serializationInputC(0);
753  Py_ssize_t len;
754  if (PyString_AsStringAndSize(serializationInput, &serializationInputC, &len))
755  throw Exception("DistributedPythonNode problem in python pickle");
756  serializationInputCorba->length(len);
757  for(int i=0; i < len ; i++)
758  serializationInputCorba[i]=serializationInputC[i];
759  Py_XDECREF(serializationInput);
760  }
761  _pynode->defineNewCustomVar(DPL_INFO_NAME,serializationInputCorba);
762  }
763  else
764  {
765  AutoGIL agil;
766  PyDict_SetItemString(_context,DPL_INFO_NAME,ob);
767  Py_XDECREF(ob);
768  }
769 }
void PythonNode::assignRemotePyInterpretor ( Engines::PyNodeBase_var  remoteInterp)
protectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 683 of file PythonNode.cxx.

References _pynode.

684 {
685  if(!CORBA::is_nil(_pynode))
686  {
687  Engines::PyScriptNode_var tmpp(Engines::PyScriptNode::_narrow(remoteInterp));
688  if(_pynode->_is_equivalent(tmpp))
689  return ;
690  }
691  if(!CORBA::is_nil(_pynode))
692  _pynode->UnRegister();
693  _pynode=Engines::PyScriptNode::_narrow(remoteInterp);
694 }
void PythonNode::checkBasicConsistency ( ) const throw (Exception)
virtual

Reimplemented from YACS::ENGINE::ElementaryNode.

Definition at line 337 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::checkBasicConsistency(), DEBTRACE, YACS::ENGINE::Node::getName(), and YACS::ENGINE::newPyStdOut().

338 {
339  DEBTRACE("checkBasicConsistency");
341  {
342  AutoGIL agil;
343  PyObject* res;
344  res=Py_CompileString(_script.c_str(),getName().c_str(),Py_file_input);
345  if(res == NULL)
346  {
347  std::string error="";
348  PyObject* new_stderr = newPyStdOut(error);
349  PySys_SetObject((char*)"stderr", new_stderr);
350  PyErr_Print();
351  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
352  Py_DECREF(new_stderr);
353  throw Exception(error);
354  }
355  else
356  Py_XDECREF(res);
357  }
358 }
PythonNode * PythonNode::cloneNode ( const std::string &  name)
virtual

Create a new node of same type with a given name.

Reimplemented from YACS::ENGINE::InlineNode.

Definition at line 702 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, DEBTRACE, YACS::ENGINE::ElementaryNode::edAddInputPort(), YACS::ENGINE::ElementaryNode::edAddOutputPort(), YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::DataPort::getName(), YACS::ENGINE::TypeCode::kind(), gui.Appli::n, p, PythonNode(), and YACS::ENGINE::InlineNode::setScript().

703 {
704  PythonNode* n=new PythonNode(name);
705  n->setScript(_script);
706  list<InputPort *>::iterator iter;
707  for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
708  {
709  InputPyPort *p=(InputPyPort *)*iter;
710  DEBTRACE( "port name: " << p->getName() );
711  DEBTRACE( "port kind: " << p->edGetType()->kind() );
712  n->edAddInputPort(p->getName(),p->edGetType());
713  }
714  list<OutputPort *>::iterator iter2;
715  for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
716  {
717  OutputPyPort *p=(OutputPyPort *)*iter2;
718  DEBTRACE( "port name: " << p->getName() );
719  DEBTRACE( "port kind: " << p->edGetType()->kind() );
720  n->edAddOutputPort(p->getName(),p->edGetType());
721  }
722  return n;
723 }
void PythonNode::createRemoteAdaptedPyInterpretor ( Engines::Container_ptr  objContainer)
protectedvirtual

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

Implements YACS::ENGINE::PythonEntry.

Definition at line 666 of file PythonNode.cxx.

References _pynode, YACS::ENGINE::Node::getName(), and YACS::ENGINE::InlineNode::getScript().

667 {
668  if(!CORBA::is_nil(_pynode))
669  _pynode->UnRegister();
670  _pynode=objContainer->createPyScriptNode(getName().c_str(),getScript().c_str());
671 }
void PythonNode::execute ( )
virtual

Implements YACS::ENGINE::Task.

Definition at line 380 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_mode, executeLocal(), executeRemote(), and REMOTE_NAME.

381 {
383  executeRemote();
384  else
385  executeLocal();
386 }
void PythonNode::executeLocal ( )
virtual

Definition at line 539 of file PythonNode.cxx.

References YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::DataPort::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::InputPyPort::getPyObj(), YACS::ENGINE::TypeCode::kind(), YACS::ENGINE::newPyStdOut(), p, YACS::ENGINE::OutputPyPort::put(), and YACS::Exception::what().

Referenced by execute().

540 {
541  DEBTRACE( "++++++++++++++ PyNode::executeLocal: " << getName() << " ++++++++++++++++++++" );
542  {
543  AutoGIL agil;
544 
545  DEBTRACE( "---------------PyNode::inputs---------------" );
546  list<InputPort *>::iterator iter2;
547  for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
548  {
549  InputPyPort *p=(InputPyPort *)*iter2;
550  DEBTRACE( "port name: " << p->getName() );
551  DEBTRACE( "port kind: " << p->edGetType()->kind() );
552  PyObject* ob=p->getPyObj();
553  DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
554 #ifdef _DEVDEBUG_
555  PyObject_Print(ob,stderr,Py_PRINT_RAW);
556  cerr << endl;
557 #endif
558  int ier=PyDict_SetItemString(_context,p->getName().c_str(),ob);
559  DEBTRACE( "after PyDict_SetItemString:ob refcnt: " << ob->ob_refcnt );
560  }
561 
562  DEBTRACE( "---------------End PyNode::inputs---------------" );
563 
564  //calculation
565  DEBTRACE( "----------------PyNode::calculation---------------" );
566  DEBTRACE( _script );
567  DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
568 
569  std::ostringstream stream;
570  stream << "/tmp/PythonNode_";
571  stream << getpid();
572 
573  PyObject* code=Py_CompileString(_script.c_str(), stream.str().c_str(), Py_file_input);
574  if(code == NULL)
575  {
576  _errorDetails="";
577  PyObject* new_stderr = newPyStdOut(_errorDetails);
578  PySys_SetObject((char*)"stderr", new_stderr);
579  PyErr_Print();
580  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
581  Py_DECREF(new_stderr);
582  throw Exception("Error during execution");
583  }
584  PyObject *res = PyEval_EvalCode((PyCodeObject *)code, _context, _context);
585 
586  Py_DECREF(code);
587  Py_XDECREF(res);
588  DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
589  fflush(stdout);
590  fflush(stderr);
591  if(PyErr_Occurred ())
592  {
593  _errorDetails="";
594  PyObject* new_stderr = newPyStdOut(_errorDetails);
595  PySys_SetObject((char*)"stderr", new_stderr);
596  ofstream errorfile(stream.str().c_str());
597  if (errorfile.is_open())
598  {
599  errorfile << _script;
600  errorfile.close();
601  }
602  PyErr_Print();
603  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
604  Py_DECREF(new_stderr);
605  throw Exception("Error during execution");
606  }
607 
608  DEBTRACE( "-----------------PyNode::outputs-----------------" );
609  list<OutputPort *>::iterator iter;
610  try
611  {
612  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
613  {
614  OutputPyPort *p=(OutputPyPort *)*iter;
615  DEBTRACE( "port name: " << p->getName() );
616  DEBTRACE( "port kind: " << p->edGetType()->kind() );
617  PyObject *ob=PyDict_GetItemString(_context,p->getName().c_str());
618  if(ob==NULL)
619  {
620  std::string msg="Error during execution: there is no variable ";
621  msg=msg+p->getName()+" in node context";
622  _errorDetails=msg;
623  throw Exception(msg);
624  }
625  DEBTRACE( "PyNode::outputs::ob refcnt: " << ob->ob_refcnt );
626 #ifdef _DEVDEBUG_
627  PyObject_Print(ob,stderr,Py_PRINT_RAW);
628  cerr << endl;
629 #endif
630  p->put(ob);
631  }
632  }
633  catch(ConversionException& ex)
634  {
635  _errorDetails=ex.what();
636  throw;
637  }
638 
639  DEBTRACE( "-----------------End PyNode::outputs-----------------" );
640  }
641  DEBTRACE( "++++++++++++++ End PyNode::execute: " << getName() << " ++++++++++++++++++++" );
642 }
void PythonNode::executeRemote ( )
virtual

Definition at line 388 of file PythonNode.cxx.

References YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::PythonEntry::_pyfuncSer, YACS::ENGINE::PythonEntry::_pyfuncUnser, _pynode, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, YACS::ENGINE::PythonEntry::commonRemoteLoadPart2(), DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::InlineNode::getContainer(), YACS::ENGINE::DataPort::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::ElementaryNode::getNumberOfOutputPorts(), YACS::ENGINE::InputPyPort::getPyObj(), YACS::ENGINE::InlineNode::getScript(), CORBAEngineTest::i, YACS::ENGINE::TypeCode::kind(), p, YACS::ENGINE::OutputPyPort::put(), and YACS::Exception::what().

Referenced by execute().

389 {
390  DEBTRACE( "++++++++++++++ PyNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
391  if(!_pyfuncSer)
392  throw Exception("DistributedPythonNode badly loaded");
393  //
394  if(dynamic_cast<HomogeneousPoolContainer *>(getContainer()))
395  {
396  bool dummy;
397  commonRemoteLoadPart2(this,dummy);
398  _pynode->assignNewCompiledCode(getScript().c_str());
399  }
400  //
401  Engines::pickledArgs_var serializationInputCorba(new Engines::pickledArgs);
402  {
403  AutoGIL agil;
404  PyObject *args(0),*ob(0);
405  //===========================================================================
406  // Get inputs in input ports, build a Python dict and pickle it
407  //===========================================================================
408  args = PyDict_New();
409  std::list<InputPort *>::iterator iter2;
410  int pos(0);
411  for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); ++iter2)
412  {
413  InputPyPort *p=(InputPyPort *)*iter2;
414  ob=p->getPyObj();
415  PyDict_SetItemString(args,p->getName().c_str(),ob);
416  pos++;
417  }
418 #ifdef _DEVDEBUG_
419  PyObject_Print(args,stderr,Py_PRINT_RAW);
420  std::cerr << endl;
421 #endif
422  PyObject *serializationInput(PyObject_CallFunctionObjArgs(_pyfuncSer,args,NULL));
423  Py_DECREF(args);
424  //The pickled string may contain NULL characters so use PyString_AsStringAndSize
425  char *serializationInputC(0);
426  Py_ssize_t len;
427  if (PyString_AsStringAndSize(serializationInput, &serializationInputC, &len))
428  throw Exception("DistributedPythonNode problem in python pickle");
429  serializationInputCorba->length(len);
430  for(int i=0; i < len ; i++)
431  serializationInputCorba[i]=serializationInputC[i];
432  Py_DECREF(serializationInput);
433  }
434 
435  //get the list of output argument names
436  std::list<OutputPort *>::iterator iter;
437  Engines::listofstring myseq;
438  myseq.length(getNumberOfOutputPorts());
439  int pos=0;
440  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); ++iter)
441  {
442  OutputPyPort *p=(OutputPyPort *)*iter;
443  myseq[pos]=p->getName().c_str();
444  DEBTRACE( "port name: " << p->getName() );
445  DEBTRACE( "port kind: " << p->edGetType()->kind() );
446  DEBTRACE( "port pos : " << pos );
447  pos++;
448  }
449  //===========================================================================
450  // Execute in remote Python node
451  //===========================================================================
452  DEBTRACE( "-----------------starting remote python invocation-----------------" );
453  Engines::pickledArgs_var resultCorba;
454  try
455  {
456  //pass outargsname and dict serialized
457  resultCorba=_pynode->execute(myseq,serializationInputCorba);
458  }
459  catch( const SALOME::SALOME_Exception& ex )
460  {
461  std::string msg="Exception on remote python invocation";
462  msg += '\n';
463  msg += ex.details.text.in();
464  _errorDetails=msg;
465  throw Exception(msg);
466  }
467  DEBTRACE( "-----------------end of remote python invocation-----------------" );
468  //===========================================================================
469  // Get results, unpickle and put them in output ports
470  //===========================================================================
471  char *resultCorbaC=new char[resultCorba->length()+1];
472  resultCorbaC[resultCorba->length()]='\0';
473  for(int i=0;i<resultCorba->length();i++)
474  resultCorbaC[i]=resultCorba[i];
475 
476  {
477  AutoGIL agil;
478  PyObject *args(0),*ob(0);
479  PyObject* resultPython=PyString_FromStringAndSize(resultCorbaC,resultCorba->length());
480  delete [] resultCorbaC;
481  args = PyTuple_New(1);
482  PyTuple_SetItem(args,0,resultPython);
483  PyObject *finalResult=PyObject_CallObject(_pyfuncUnser,args);
484  Py_DECREF(args);
485 
486  if (finalResult == NULL)
487  {
488  std::stringstream msg;
489  msg << "Conversion with pickle of output ports failed !";
490  msg << " : " << __FILE__ << ":" << __LINE__;
491  _errorDetails=msg.str();
492  throw YACS::ENGINE::ConversionException(msg.str());
493  }
494 
495  DEBTRACE( "-----------------PythonNode::outputs-----------------" );
496  int nres=1;
497  if(finalResult == Py_None)
498  nres=0;
499  else if(PyTuple_Check(finalResult))
500  nres=PyTuple_Size(finalResult);
501 
502  if(getNumberOfOutputPorts() != nres)
503  {
504  std::string msg="Number of output arguments : Mismatch between definition and execution";
505  Py_DECREF(finalResult);
506  _errorDetails=msg;
507  throw Exception(msg);
508  }
509 
510  pos=0;
511  try
512  {
513  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); ++iter)
514  {
515  OutputPyPort *p=(OutputPyPort *)*iter;
516  DEBTRACE( "port name: " << p->getName() );
517  DEBTRACE( "port kind: " << p->edGetType()->kind() );
518  DEBTRACE( "port pos : " << pos );
519  if(PyTuple_Check(finalResult))
520  ob=PyTuple_GetItem(finalResult,pos) ;
521  else
522  ob=finalResult;
523  DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
524  p->put(ob);
525  pos++;
526  }
527  Py_DECREF(finalResult);
528  }
529  catch(ConversionException& ex)
530  {
531  Py_DECREF(finalResult);
532  _errorDetails=ex.what();
533  throw;
534  }
535  }
536  DEBTRACE( "++++++++++++++ ENDOF PyNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
537 }
std::string PythonNode::getContainerLog ( )
virtual

returns a string that contains the name of the container log file if it exists

Do nothing here. To subclass

Reimplemented from YACS::ENGINE::Node.

Definition at line 644 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_container, YACS::ENGINE::InlineNode::_mode, and YACS::ENGINE::PythonEntry::GetContainerLog().

645 {
647 }
Engines::PyNodeBase_var PythonNode::getRemoteInterpreterHandle ( )
protectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 696 of file PythonNode.cxx.

References _pynode.

697 {
698  return Engines::PyNodeBase::_narrow(_pynode);
699 }
const char* YACS::ENGINE::PythonNode::getSerializationScript ( ) const
inlineprotectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 71 of file PythonNode.hxx.

71 { return SCRIPT_FOR_SERIALIZATION; }
void PythonNode::load ( )
virtual

Reimplemented from YACS::ENGINE::ElementaryNode.

Definition at line 360 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_mode, DEBTRACE, loadLocal(), loadRemote(), and REMOTE_NAME.

361 {
362  DEBTRACE( "---------------PyNode::load function---------------" );
364  loadRemote();
365  else
366  loadLocal();
367 }
void PythonNode::loadLocal ( )
virtual

Definition at line 369 of file PythonNode.cxx.

References DEBTRACE.

Referenced by load().

370 {
371  DEBTRACE( "---------------PyNode::loadLocal function---------------" );
372  // do nothing
373 }
void PythonNode::loadRemote ( )
virtual

Definition at line 375 of file PythonNode.cxx.

References YACS::ENGINE::PythonEntry::commonRemoteLoad().

Referenced by load().

376 {
377  commonRemoteLoad(this);
378 }
Engines::PyNodeBase_var PythonNode::retrieveDftRemotePyInterpretorIfAny ( Engines::Container_ptr  objContainer) const
protectedvirtual

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

Implements YACS::ENGINE::PythonEntry.

Definition at line 673 of file PythonNode.cxx.

References YACS::ENGINE::Node::getName(), and PMMLBasicsTestLauncher::ret.

674 {
675  Engines::PyScriptNode_var ret(objContainer->getDefaultPyScriptNode(getName().c_str()));
676  if(!CORBA::is_nil(ret))
677  {
678  ret->Register();
679  }
680  return Engines::PyNodeBase::_narrow(ret);
681 }
void PythonNode::shutdown ( int  level)
virtual

Stop all pending activities of the node.

This method should be called when a Proc is finished and must be deleted from the YACS server

Reimplemented from YACS::ENGINE::Node.

Definition at line 649 of file PythonNode.cxx.

References YACS::ENGINE::InlineNode::_container, YACS::ENGINE::InlineNode::_mode, _pynode, DEBTRACE, and YACS::ENGINE::Container::shutdown().

650 {
651  DEBTRACE("PythonNode::shutdown " << level);
652  if(_mode=="local")return;
653  if(_container)
654  {
655  if(!CORBA::is_nil(_pynode)) _pynode->UnRegister();
656  _pynode=Engines::PyScriptNode::_nil();
657  _container->shutdown(level);
658  }
659 }
Node * PythonNode::simpleClone ( ComposedNode father,
bool  editionOnly 
) const
protectedvirtual

Implements YACS::ENGINE::Node.

Definition at line 661 of file PythonNode.cxx.

References PythonNode().

662 {
663  return new PythonNode(*this,father);
664 }
virtual std::string YACS::ENGINE::PythonNode::typeName ( )
inlinevirtual

Reimplemented from YACS::ENGINE::InlineNode.

Definition at line 86 of file PythonNode.hxx.

86 { return "YACS__ENGINE__PythonNode"; }

Member Data Documentation

Engines::PyScriptNode_var YACS::ENGINE::PythonNode::_pynode
protected
const char PythonNode::DPL_INFO_NAME ="my_dpl_localization"
static

Definition at line 93 of file PythonNode.hxx.

Referenced by applyDPLScope().

const char PythonNode::IMPL_NAME ="Python"
static
const char PythonNode::KIND ="Python"
static

Definition at line 89 of file PythonNode.hxx.

Referenced by YACS::ENGINE::DistributedPythonNode::getKind().

const char PythonNode::REMOTE_NAME ="remote"
static
const char PythonNode::SCRIPT_FOR_SERIALIZATION
static
Initial value:
="import cPickle\n"
"def pickleForDistPyth2009(kws):\n"
" return cPickle.dumps(((),kws),-1)\n"
"\n"
"def unPickleForDistPyth2009(st):\n"
" args=cPickle.loads(st)\n"
" return args\n"

Definition at line 91 of file PythonNode.hxx.


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