Version: 9.15.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
 
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...
 
void imposeResource (const std::string &resource_name, const std::string &container_name) override
 
bool canAcceptImposedResource () override
 
bool hasImposedResource () const override
 
bool isUsingPythonCache () const
 
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)
 
void setSqueezeStatusWithExceptions (bool sqStatus, const std::vector< std::string > &squeezeExceptions)
 
void setSqueezeStatus (bool sqStatus)
 
bool getSqueezeStatus () const
 
void squeezeMemorySafe ()
 
- 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)
 
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 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 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 Member Functions

static void ExecuteLocalInternal (const std::string &codeStr, PyObject *context, std::string &errorDetails)
 
- 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)
 
- Static Public Member Functions inherited from YACS::ENGINE::PythonEntry
static bool IsProxy (PyObject *ob)
 
static bool GetDestroyStatus (PyObject *ob)
 
static void DoNotTouchFileIfProxy (PyObject *ob)
 
static void UnlinkOnDestructorIfProxy (PyObject *ob)
 
static void IfProxyDoSomething (PyObject *ob, const char *meth)
 

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::Node
static std::map< int, Node * > idMap
 
- 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
 
std::string pythonEntryName () const
 
void squeezeMemory ()
 
void squeezeMemoryRemote ()
 
void freeKernelPynode ()
 
- 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 Member Functions inherited from YACS::ENGINE::PythonEntry
 PythonEntry ()
 
 ~PythonEntry ()
 
void commonRemoteLoad (InlineNode *reqNode)
 
void loadRemoteContainer (InlineNode *reqNode)
 
Engines::Container_var loadPythonAdapter (InlineNode *reqNode, bool &isInitializeRequested)
 
void loadRemoteContext (InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested)
 

Protected Attributes

bool _autoSqueeze = false
 
std::set< std::string > _nonSqueezableOutputNodes
 list on output port name excluded from the squeeze mecanism More...
 
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
 
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
 
- Protected Attributes inherited from YACS::ENGINE::PythonEntry
PyObject * _context
 
PyObject * _pyfuncSer
 
PyObject * _pyfuncUnser
 
PyObject * _pyfuncSimpleSer
 
std::string _imposedResource
 
std::string _imposedContainer
 

Private Member Functions

void executeLocalInternal (const std::string &codeStr)
 

Additional Inherited Members

- 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 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
 
- Static Protected Attributes inherited from YACS::ENGINE::PythonEntry
static PyObject * _pyClsBigObject = nullptr
 

Detailed Description

Definition at line 75 of file PythonNode.hxx.

Constructor & Destructor Documentation

◆ PythonNode() [1/2]

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

Definition at line 418 of file PythonNode.cxx.

418  :
420 {
421  _pynode = Engines::PyScriptNode::_nil();
423  {
424  AutoGIL agil;
425  _context=PyDict_New();
426  if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
427  {
428  stringstream msg;
429  msg << "Impossible to set builtins" << __FILE__ << ":" << __LINE__;
430  _errorDetails=msg.str();
431  throw Exception(msg.str());
432  }
433  }
434 }
InlineNode(const InlineNode &other, ComposedNode *father)
Definition: InlineNode.hxx:46
std::string _implementation
Definition: Node.hxx:97
std::string _errorDetails
Definition: Node.hxx:93
Engines::PyScriptNode_var _pynode
Definition: PythonNode.hxx:131
static const char IMPL_NAME[]
Definition: PythonNode.hxx:123
std::set< std::string > _nonSqueezableOutputNodes
list on output port name excluded from the squeeze mecanism
Definition: PythonNode.hxx:130
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()

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

Referenced by cloneNode(), and simpleClone().

◆ PythonNode() [2/2]

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

Definition at line 436 of file PythonNode.cxx.

436  :InlineNode(name)
437 {
438  _pynode = Engines::PyScriptNode::_nil();
440  {
441  AutoGIL agil;
442  _context=PyDict_New();
443  if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
444  {
445  stringstream msg;
446  msg << "Impossible to set builtins" << __FILE__ << ":" << __LINE__;
447  _errorDetails=msg.str();
448  throw Exception(msg.str());
449  }
450  }
451 }

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

◆ ~PythonNode()

PythonNode::~PythonNode ( )
virtual

Definition at line 453 of file PythonNode.cxx.

454 {
456 }

References freeKernelPynode().

Member Function Documentation

◆ applyDPLScope()

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 1047 of file PythonNode.cxx.

1048 {
1049  std::vector< std::pair<std::string,int> > ret(getDPLScopeInfo(gfn));
1050  if(ret.empty())
1051  return ;
1052  //
1053  PyObject *ob(0);
1054  {
1055  AutoGIL agil;
1056  std::size_t sz(ret.size());
1057  ob=PyList_New(sz);
1058  for(std::size_t i=0;i<sz;i++)
1059  {
1060  const std::pair<std::string,int>& p(ret[i]);
1061  PyObject *elt(PyTuple_New(2));
1062  PyTuple_SetItem(elt,0,PyUnicode_FromString(p.first.c_str()));
1063  PyTuple_SetItem(elt,1,PyLong_FromLong(p.second));
1064  PyList_SetItem(ob,i,elt);
1065  }
1066  }
1067  if(_mode==REMOTE_NAME)
1068  {
1069  Engines::pickledArgs_var serializationInputCorba(new Engines::pickledArgs);
1070  {
1071  AutoGIL agil;
1072  PyObject *serializationInput(PyObject_CallFunctionObjArgs(_pyfuncSimpleSer,ob,NULL));
1073  Py_XDECREF(ob);
1074  char *serializationInputC(0);
1075  Py_ssize_t len;
1076  if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
1077  throw Exception("DistributedPythonNode problem in python pickle");
1078  serializationInputCorba->length(len);
1079  for(int i=0; i < len ; i++)
1080  serializationInputCorba[i]=serializationInputC[i];
1081  Py_XDECREF(serializationInput);
1082  }
1083  _pynode->defineNewCustomVar(DPL_INFO_NAME,serializationInputCorba);
1084  }
1085  else
1086  {
1087  AutoGIL agil;
1088  PyDict_SetItemString(_context,DPL_INFO_NAME,ob);
1089  Py_XDECREF(ob);
1090  }
1091 }
int Py_ssize_t
Definition: PythonNode.cxx:45
std::vector< std::pair< std::string, int > > getDPLScopeInfo(ComposedNode *gfn)
Definition: Node.cxx:660
static const char REMOTE_NAME[]
Definition: PythonNode.hxx:125
static const char DPL_INFO_NAME[]
Definition: PythonNode.hxx:126
Proc * p
Definition: driver.cxx:216

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

◆ assignRemotePyInterpretor()

void PythonNode::assignRemotePyInterpretor ( Engines::PyNodeBase_var  remoteInterp)
protectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 1002 of file PythonNode.cxx.

1003 {
1004  if(CORBA::is_nil(_pynode))
1005  _pynode=Engines::PyScriptNode::_narrow(remoteInterp);
1006  else
1007  {
1008  Engines::PyScriptNode_var tmpp(Engines::PyScriptNode::_narrow(remoteInterp));
1009  if(!_pynode->_is_equivalent(tmpp))
1010  {
1011  freeKernelPynode();
1012  _pynode=Engines::PyScriptNode::_narrow(remoteInterp);
1013  }
1014  }
1015  _pynode->assignNewCompiledCode(getScript().c_str());
1016 }
virtual std::string getScript()
Definition: InlineNode.hxx:51

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

◆ canAcceptImposedResource()

bool PythonNode::canAcceptImposedResource ( )
overridevirtual

Reimplemented from YACS::ENGINE::Task.

Definition at line 938 of file PythonNode.cxx.

939 {
940  return _container != nullptr && _container->canAcceptImposedResource();
941 }
virtual bool canAcceptImposedResource()
Definition: Container.cxx:59

References YACS::ENGINE::InlineNode::_container, and YACS::ENGINE::Container::canAcceptImposedResource().

◆ checkBasicConsistency()

void PythonNode::checkBasicConsistency ( ) const
virtual

Reimplemented from YACS::ENGINE::ElementaryNode.

Definition at line 458 of file PythonNode.cxx.

459 {
460  DEBTRACE("checkBasicConsistency");
462  {
463  AutoGIL agil;
464  PyObject* res;
465  res=Py_CompileString(_script.c_str(),getName().c_str(),Py_file_input);
466  if(res == NULL)
467  {
468  std::string error="";
469  PyObject* new_stderr = newPyStdOut(error);
470  PySys_SetObject((char*)"stderr", new_stderr);
471  PyErr_Print();
472  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
473  Py_DECREF(new_stderr);
474  throw Exception(error);
475  }
476  else
477  Py_XDECREF(res);
478  }
479 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
virtual void checkBasicConsistency() const
const std::string & getName() const
Definition: Node.hxx:125
PyObject * newPyStdOut(std::string &out)
Definition: PyStdout.cxx:129

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

◆ cloneNode()

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 1024 of file PythonNode.cxx.

1025 {
1026  PythonNode* n=new PythonNode(name);
1027  n->setScript(_script);
1028  list<InputPort *>::iterator iter;
1029  for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
1030  {
1031  InputPyPort *p=(InputPyPort *)*iter;
1032  DEBTRACE( "port name: " << p->getName() );
1033  DEBTRACE( "port kind: " << p->edGetType()->kind() );
1034  n->edAddInputPort(p->getName(),p->edGetType());
1035  }
1036  list<OutputPort *>::iterator iter2;
1037  for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
1038  {
1039  OutputPyPort *p=(OutputPyPort *)*iter2;
1040  DEBTRACE( "port name: " << p->getName() );
1041  DEBTRACE( "port kind: " << p->edGetType()->kind() );
1042  n->edAddOutputPort(p->getName(),p->edGetType());
1043  }
1044  return n;
1045 }
std::string getName() const
std::list< InputPort * > _setOfInputPort
std::list< OutputPort * > _setOfOutputPort
Class for Python Ports.
Definition: PythonPorts.hxx:74
PythonNode(const PythonNode &other, ComposedNode *father)
Definition: PythonNode.cxx:418

References YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, DEBTRACE, YACS::ENGINE::ComposedNode::getName(), gui.Appli::n, p, and PythonNode().

◆ createRemoteAdaptedPyInterpretor()

void PythonNode::createRemoteAdaptedPyInterpretor ( Engines::Container_ptr  objContainer)
protectedvirtual

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

Implements YACS::ENGINE::PythonEntry.

Definition at line 985 of file PythonNode.cxx.

986 {
988  _pynode=objContainer->createPyScriptNode(pythonEntryName().c_str(),getScript().c_str());
989  _pynode->Register();
990 }
std::string pythonEntryName() const
Definition: PythonNode.cxx:948

References _pynode, freeKernelPynode(), YACS::ENGINE::InlineNode::getScript(), and pythonEntryName().

◆ execute()

void PythonNode::execute ( )
virtual

Implements YACS::ENGINE::Task.

Definition at line 501 of file PythonNode.cxx.

502 {
504  executeRemote();
505  else
506  executeLocal();
507 }
virtual void executeRemote()
Definition: PythonNode.cxx:509
virtual void executeLocal()
Definition: PythonNode.cxx:775

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

◆ executeLocal()

void PythonNode::executeLocal ( )
virtual

Definition at line 775 of file PythonNode.cxx.

776 {
777  DEBTRACE( "++++++++++++++ PyNode::executeLocal: " << getName() << " ++++++++++++++++++++" );
778  {
779  AutoGIL agil;
780  std::ostringstream unpxy; unpxy << "from SALOME_PyNode import UnProxyObjectSimpleLocal" << std::endl;
781  DEBTRACE( "---------------PyNode::inputs---------------" );
782  list<InputPort *>::iterator iter2;
783  for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
784  {
785  InputPyPort *p=(InputPyPort *)*iter2;
786  DEBTRACE( "port name: " << p->getName() );
787  DEBTRACE( "port kind: " << p->edGetType()->kind() );
788  PyObject* ob=p->getPyObj();
789  DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
790  unpxy << p->getName() << " = UnProxyObjectSimpleLocal( " << p->getName() << " )" << std::endl;
791 #ifdef _DEVDEBUG_
792  PyObject_Print(ob,stderr,Py_PRINT_RAW);
793  cerr << endl;
794 #endif
795  int ier=PyDict_SetItemString(_context,p->getName().c_str(),ob);
796  DEBTRACE( "after PyDict_SetItemString:ob refcnt: " << ob->ob_refcnt );
797  }
798 
799  DEBTRACE( "---------------End PyNode::inputs---------------" );
800 
801  //calculation
802  DEBTRACE( "----------------PyNode::calculation---------------" );
803 
804  if( ! getSqueezeStatus() )
805  executeLocalInternal( unpxy.str() );
806 
808 
809  DEBTRACE( "-----------------PyNode::outputs-----------------" );
810  list<OutputPort *>::iterator iter;
811  try
812  {
813  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
814  {
815  OutputPyPort *p=(OutputPyPort *)*iter;
816  DEBTRACE( "port name: " << p->getName() );
817  DEBTRACE( "port kind: " << p->edGetType()->kind() );
818  PyObject *ob=PyDict_GetItemString(_context,p->getName().c_str());
819  if(ob==NULL)
820  {
821  std::string msg="Error during execution: there is no variable ";
822  msg=msg+p->getName()+" in node context";
823  _errorDetails=msg;
824  throw Exception(msg);
825  }
826  DEBTRACE( "PyNode::outputs::ob refcnt: " << ob->ob_refcnt );
827 #ifdef _DEVDEBUG_
828  PyObject_Print(ob,stderr,Py_PRINT_RAW);
829  cerr << endl;
830 #endif
831  p->put(ob);
832  if(!isUsingPythonCache())
833  PyDict_DelItemString(_context,p->getName().c_str());
834  }
835  }
836  catch(ConversionException& ex)
837  {
838  _errorDetails=ex.what();
839  throw;
840  }
841  if(_autoSqueeze)
842  squeezeMemory();
843  DEBTRACE( "-----------------End PyNode::outputs-----------------" );
844  if(!isUsingPythonCache())
845  {
846  for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
847  {
848  AutoPyRef pStr = PyUnicode_FromString( (*iter2)->getName().c_str() );
849  if( PyDict_Contains(_context,pStr) == 1 )
850  { PyDict_DelItem(_context,pStr); }
851  }
852  }
853  }
854  DEBTRACE( "++++++++++++++ End PyNode::execute: " << getName() << " ++++++++++++++++++++" );
855 }
bool isUsingPythonCache() const
Definition: PythonNode.cxx:956
void executeLocalInternal(const std::string &codeStr)
Definition: PythonNode.cxx:770
bool getSqueezeStatus() const
Definition: PythonNode.hxx:112

References _autoSqueeze, YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, DEBTRACE, testCppPluginInvokation::ex, executeLocalInternal(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getName(), getSqueezeStatus(), isUsingPythonCache(), p, and squeezeMemory().

Referenced by execute().

◆ executeLocalInternal()

void PythonNode::executeLocalInternal ( const std::string &  codeStr)
private

Definition at line 770 of file PythonNode.cxx.

771 {
773 }
static void ExecuteLocalInternal(const std::string &codeStr, PyObject *context, std::string &errorDetails)
Definition: PythonNode.cxx:730

References YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::Node::_errorDetails, and ExecuteLocalInternal().

Referenced by executeLocal().

◆ ExecuteLocalInternal()

void PythonNode::ExecuteLocalInternal ( const std::string &  codeStr,
PyObject *  context,
std::string &  errorDetails 
)
static

Definition at line 730 of file PythonNode.cxx.

731 {
732  DEBTRACE( code );
733  DEBTRACE( "context refcnt: " << context->ob_refcnt );
734  std::ostringstream stream;
735  stream << "/tmp/PythonNode_";
736  stream << getpid();
737  AutoPyRef code=Py_CompileString(codeStr.c_str(), stream.str().c_str(), Py_file_input);
738  if(code == NULL)
739  {
740  errorDetails="";
741  AutoPyRef new_stderr = newPyStdOut(errorDetails);
742  PySys_SetObject((char*)"stderr", new_stderr);
743  PyErr_Print();
744  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
745  throw YACS::Exception("Error during execution");
746  }
747  {
748  AutoPyRef res = PyEval_EvalCode( code, context, context);
749  }
750  DEBTRACE( "context refcnt: " << context->ob_refcnt );
751  fflush(stdout);
752  fflush(stderr);
753  if(PyErr_Occurred ())
754  {
755  errorDetails="";
756  AutoPyRef new_stderr = newPyStdOut(errorDetails);
757  PySys_SetObject((char*)"stderr", new_stderr);
758  ofstream errorfile(stream.str().c_str());
759  if (errorfile.is_open())
760  {
761  errorfile << codeStr;
762  errorfile.close();
763  }
764  PyErr_Print();
765  PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
766  throw YACS::Exception("Error during execution");
767  }
768 }

References DEBTRACE, and YACS::ENGINE::newPyStdOut().

Referenced by executeLocalInternal().

◆ executeRemote()

void PythonNode::executeRemote ( )
virtual

Definition at line 509 of file PythonNode.cxx.

510 {
511  DEBTRACE( "++++++++++++++ PyNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
512  if(!_pyfuncSer)
513  throw Exception("PythonNode badly loaded");
514  //
515  if(dynamic_cast<HomogeneousPoolContainer *>(getContainer()))
516  {
517  bool dummy;
518  loadPythonAdapter(this,dummy);
519  _pynode->assignNewCompiledCode(getScript().c_str());
520  }
521  // not managed by unique_ptr here because destructed by the order of client.
522  SenderByteImpl *serializationInputCorba = nullptr;
523  AutoPyRef serializationInput;
524  {
525 #if PY_VERSION_HEX < 0x03070000
526  std::unique_lock<std::mutex> lock(data_mutex);
527 #endif
528  AutoGIL agil;
529  PyObject *args(0),*ob(0);
530  //===========================================================================
531  // Get inputs in input ports, build a Python dict and pickle it
532  //===========================================================================
533  args = PyDict_New();
534  std::list<InputPort *>::iterator iter2;
535  int pos(0);
536  for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); ++iter2)
537  {
538  InputPyPort *p=(InputPyPort *)*iter2;
539  ob=p->getPyObj();
540  PyDict_SetItemString(args,p->getName().c_str(),ob);
541  pos++;
542  }
543 #ifdef _DEVDEBUG_
544  PyObject_Print(args,stderr,Py_PRINT_RAW);
545  std::cerr << endl;
546 #endif
547  serializationInput.set(PyObject_CallFunctionObjArgs(_pyfuncSer,args,nullptr));
548  Py_DECREF(args);
549  //The pickled string may contain NULL characters so use PyString_AsStringAndSize
550  char *serializationInputC(nullptr);
551  Py_ssize_t len;
552  if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
553  throw Exception("DistributedPythonNode problem in python pickle");
554  // no copy here. The C byte array of Python is taken as this into CORBA sequence to avoid copy
555  serializationInputCorba = new SenderByteImpl(serializationInputC,len);
556  }
557 
558  //get the list of output argument names
559  std::list<OutputPort *>::iterator iter;
560  Engines::listofstring myseq;
561  myseq.length(getNumberOfOutputPorts());
562  int pos=0;
563  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); ++iter)
564  {
565  OutputPyPort *p=(OutputPyPort *)*iter;
566  myseq[pos]=p->getName().c_str();
567  DEBTRACE( "port name: " << p->getName() );
568  DEBTRACE( "port kind: " << p->edGetType()->kind() );
569  DEBTRACE( "port pos : " << pos );
570  pos++;
571  }
572  //===========================================================================
573  // Execute in remote Python node
574  //===========================================================================
575  DEBTRACE( "-----------------starting remote python invocation-----------------" );
576  std::unique_ptr<SALOME::SenderByteSeq> resultCorba;
577  try
578  {
579  //pass outargsname and dict serialized
580  SALOME::SenderByte_var serializationInputRef = serializationInputCorba->_this();
581  DEBUG_YACSTRACE("Before execute first of " << getId());
582  _pynode->executeFirst(serializationInputRef);
583  //serializationInput and serializationInputCorba are no more needed for server. Release it.
584  serializationInput.set(nullptr);
585  resultCorba.reset( _pynode->executeSecond(myseq) );
586  DEBUG_YACSTRACE("After execute second of " << getId());
587  }
588  catch( const SALOME::SALOME_Exception& ex )
589  {
590  std::ostringstream msg; msg << "Exception on remote python invocation" << std::endl << ex.details.text.in() << std::endl;
591  msg << "PyScriptNode CORBA ref : ";
592  {
593  CORBA::ORB_ptr orb(getSALOMERuntime()->getOrb());
594  if(!CORBA::is_nil(orb))
595  {
596  CORBA::String_var IOR(orb->object_to_string(_pynode));
597  msg << IOR;
598  }
599  }
600  msg << std::endl;
601  _errorDetails=msg.str();
602  throw Exception(msg.str());
603  }
604  catch(CORBA::COMM_FAILURE& ex)
605  {
606  std::ostringstream msg;
607  msg << "Exception on remote python invocation." << std::endl ;
608  msg << "Caught system exception COMM_FAILURE -- unable to contact the "
609  << "object." << std::endl;
610  _errorDetails=msg.str();
611  throw Exception(msg.str());
612  }
613  catch(CORBA::SystemException& ex)
614  {
615  std::ostringstream msg;
616  msg << "Exception on remote python invocation." << std::endl ;
617  msg << "Caught a CORBA::SystemException." ;
618  CORBA::Any tmp;
619  tmp <<= ex;
620  CORBA::TypeCode_var tc = tmp.type();
621  const char *p = tc->name();
622  if ( *p != '\0' )
623  msg <<p;
624  else
625  msg << tc->id();
626  msg << std::endl;
627  _errorDetails=msg.str();
628  throw Exception(msg.str());
629  }
630  catch(CORBA::Exception& ex)
631  {
632  std::ostringstream msg;
633  msg << "Exception on remote python invocation." << std::endl ;
634  msg << "Caught CORBA::Exception. " ;
635  CORBA::Any tmp;
636  tmp <<= ex;
637  CORBA::TypeCode_var tc = tmp.type();
638  const char *p = tc->name();
639  if ( *p != '\0' )
640  msg <<p;
641  else
642  msg << tc->id();
643  msg << std::endl;
644  _errorDetails=msg.str();
645  throw Exception(msg.str());
646  }
647  catch(omniORB::fatalException& fe)
648  {
649  std::ostringstream msg;
650  msg << "Exception on remote python invocation." << std::endl ;
651  msg << "Caught omniORB::fatalException:" << std::endl;
652  msg << " file: " << fe.file() << std::endl;
653  msg << " line: " << fe.line() << std::endl;
654  msg << " mesg: " << fe.errmsg() << std::endl;
655  _errorDetails=msg.str();
656  throw Exception(msg.str());
657  }
658  DEBTRACE( "-----------------end of remote python invocation-----------------" );
659  //===========================================================================
660  // Get results, unpickle and put them in output ports
661  //===========================================================================
662  {
663 #if PY_VERSION_HEX < 0x03070000
664  std::unique_lock<std::mutex> lock(data_mutex);
665 #endif
666  AutoGIL agil;
667  DEBTRACE( "-----------------PythonNode::outputs-----------------" );
668  int nres( resultCorba->length() );
669 
670  if(getNumberOfOutputPorts() != nres)
671  {
672  std::string msg="Number of output arguments : Mismatch between definition and execution";
673  _errorDetails=msg;
674  throw Exception(msg);
675  }
676  pos=0;
677  try
678  {
679  for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); ++iter)
680  {
681  OutputPyPort *p=(OutputPyPort *)*iter;
682  DEBUG_YACSTRACE("Start of dealing with output " << p->getName() << " of "<< getId());
683  DEBTRACE( "port name: " << p->getName() );
684  DEBTRACE( "port kind: " << p->edGetType()->kind() );
685  DEBTRACE( "port pos : " << pos );
686  SALOME::SenderByte_var elt = (*resultCorba)[pos];
687  SeqByteReceiver recv(elt);
688  unsigned long length = 0;
689  char *resultCorbaC = recv.data(length);
690  {
691  AutoPyRef resultPython=PyMemoryView_FromMemory(resultCorbaC,length,PyBUF_READ);
692  AutoPyRef args = PyTuple_New(1);
693  PyTuple_SetItem(args,0,resultPython.retn());
694  AutoPyRef ob = PyObject_CallObject(_pyfuncUnser,args);
695  if (!ob)
696  {
697  std::stringstream msg;
698  msg << "Conversion with pickle of output ports failed !";
699  msg << " : " << __FILE__ << ":" << __LINE__;
700  _errorDetails=msg.str();
701  throw YACS::ENGINE::ConversionException(msg.str());
702  }
704  DEBUG_YACSTRACE("Assign PyObj output " << p->getName() << " of "<< getId());
705  p->put( ob );
706  DEBUG_YACSTRACE("End of assign PyObj output " << p->getName() << " of "<< getId());
707  }
708  pos++;
709  }
710  }
711  catch(ConversionException& ex)
712  {
713  _errorDetails=ex.what();
714  throw;
715  }
716  if(_autoSqueeze)
718  }
719  //
720  if(!isUsingPythonCache())
721  {
723  bool dummy;
724  Engines::Container_var cont(GetContainerObj(this,dummy));
725  cont->removePyScriptNode(getId().c_str());
726  }
727  DEBTRACE( "++++++++++++++ ENDOF PyNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
728 }
static std::mutex data_mutex
Definition: PythonNode.cxx:90
Engines::Container_var GetContainerObj(InlineNode *reqNode, bool &isStandardCont)
Definition: PythonNode.cxx:139
#define DEBUG_YACSTRACE(msg)
Definition: YacsTrace.hxx:53
virtual Container * getContainer()
Definition: InlineNode.cxx:100
const std::string getId() const
Definition: Node.cxx:478
static void UnlinkOnDestructorIfProxy(PyObject *ob)
Definition: PythonNode.cxx:413
Engines::Container_var loadPythonAdapter(InlineNode *reqNode, bool &isInitializeRequested)
Definition: PythonNode.cxx:165
CORBA::ORB_ptr orb
Definition: yacsSrv.cxx:39

References _autoSqueeze, YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::PythonEntry::_pyfuncSer, YACS::ENGINE::PythonEntry::_pyfuncUnser, _pynode, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, driver_internal::args, data_mutex, DEBTRACE, DEBUG_YACSTRACE, testCppPluginInvokation::ex, freeKernelPynode(), YACS::ENGINE::InlineNode::getContainer(), GetContainerObj(), YACS::ENGINE::Node::getId(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::ElementaryNode::getNumberOfOutputPorts(), YACS::ENGINE::getSALOMERuntime(), YACS::ENGINE::InlineNode::getScript(), isUsingPythonCache(), YACS::ENGINE::PythonEntry::loadPythonAdapter(), orb, p, squeezeMemoryRemote(), and YACS::ENGINE::PythonEntry::UnlinkOnDestructorIfProxy().

Referenced by execute().

◆ freeKernelPynode()

void PythonNode::freeKernelPynode ( )
protected

Definition at line 964 of file PythonNode.cxx.

965 {
966  if(!CORBA::is_nil(_pynode))
967  {
968  try
969  {
970  _pynode->UnRegister();
971  }
972  catch(...)
973  {
974  DEBTRACE("Trouble when pynode->UnRegister!")
975  }
976  _pynode = Engines::PyScriptNode::_nil();
977  }
978 }

References _pynode, and DEBTRACE.

Referenced by assignRemotePyInterpretor(), createRemoteAdaptedPyInterpretor(), executeRemote(), shutdown(), and ~PythonNode().

◆ getContainerLog()

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 912 of file PythonNode.cxx.

913 {
915 }
static std::string GetContainerLog(const std::string &mode, Container *container, const Task *askingTask)
Definition: PythonNode.cxx:283

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

◆ getRemoteInterpreterHandle()

Engines::PyNodeBase_var PythonNode::getRemoteInterpreterHandle ( )
protectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 1018 of file PythonNode.cxx.

1019 {
1020  return Engines::PyNodeBase::_narrow(_pynode);
1021 }

References _pynode.

◆ getSerializationScript()

const char* YACS::ENGINE::PythonNode::getSerializationScript ( ) const
inlineprotectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 84 of file PythonNode.hxx.

84 { return SCRIPT_FOR_SERIALIZATION; }
static const char SCRIPT_FOR_SERIALIZATION[]
Definition: PythonNode.hxx:124

◆ getSqueezeStatus()

bool YACS::ENGINE::PythonNode::getSqueezeStatus ( ) const
inline

Definition at line 112 of file PythonNode.hxx.

112 { return _autoSqueeze; }

Referenced by executeLocal().

◆ hasImposedResource()

bool PythonNode::hasImposedResource ( ) const
overridevirtual

Reimplemented from YACS::ENGINE::PythonEntry.

Definition at line 943 of file PythonNode.cxx.

944 {
946 }
virtual bool hasImposedResource() const
Definition: PythonNode.cxx:326

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

◆ imposeResource()

void PythonNode::imposeResource ( const std::string &  resource_name,
const std::string &  container_name 
)
overridevirtual

Reimplemented from YACS::ENGINE::Task.

Definition at line 928 of file PythonNode.cxx.

930 {
931  if(!resource_name.empty() && !container_name.empty())
932  {
933  _imposedResource = resource_name;
934  _imposedContainer = container_name;
935  }
936 }
std::string _imposedResource
Definition: PythonNode.hxx:69
std::string _imposedContainer
Definition: PythonNode.hxx:70

References YACS::ENGINE::PythonEntry::_imposedContainer, and YACS::ENGINE::PythonEntry::_imposedResource.

◆ isUsingPythonCache()

bool PythonNode::isUsingPythonCache ( ) const

Definition at line 956 of file PythonNode.cxx.

957 {
958  bool found = false;
959  if(_container)
960  found = _container->isUsingPythonCache();
961  return found;
962 }
virtual bool isUsingPythonCache()
Definition: Container.cxx:109

References YACS::ENGINE::InlineNode::_container, and YACS::ENGINE::Container::isUsingPythonCache().

Referenced by executeLocal(), executeRemote(), and pythonEntryName().

◆ load()

void PythonNode::load ( )
virtual

Reimplemented from YACS::ENGINE::ElementaryNode.

Definition at line 481 of file PythonNode.cxx.

482 {
483  DEBTRACE( "---------------PyNode::load function---------------" );
485  loadRemote();
486  else
487  loadLocal();
488 }
virtual void loadLocal()
Definition: PythonNode.cxx:490
virtual void loadRemote()
Definition: PythonNode.cxx:496

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

◆ loadLocal()

void PythonNode::loadLocal ( )
virtual

Definition at line 490 of file PythonNode.cxx.

491 {
492  DEBTRACE( "---------------PyNode::loadLocal function---------------" );
493  // do nothing
494 }

References DEBTRACE.

Referenced by load().

◆ loadRemote()

void PythonNode::loadRemote ( )
virtual

Definition at line 496 of file PythonNode.cxx.

497 {
498  commonRemoteLoad(this);
499 }
void commonRemoteLoad(InlineNode *reqNode)
Definition: PythonNode.cxx:318

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

Referenced by load().

◆ pythonEntryName()

std::string PythonNode::pythonEntryName ( ) const
protected

Definition at line 948 of file PythonNode.cxx.

949 {
950  if(isUsingPythonCache())
951  return "DEFAULT_NAME_FOR_UNIQUE_PYTHON_NODE_ENTRY";
952  else
953  return getId();
954 }

References YACS::ENGINE::Node::getId(), and isUsingPythonCache().

Referenced by createRemoteAdaptedPyInterpretor(), and retrieveDftRemotePyInterpretorIfAny().

◆ retrieveDftRemotePyInterpretorIfAny()

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 992 of file PythonNode.cxx.

993 {
994  Engines::PyScriptNode_var ret(objContainer->getDefaultPyScriptNode(pythonEntryName().c_str()));
995  if(!CORBA::is_nil(ret))
996  {
997  ret->Register();
998  }
999  return Engines::PyNodeBase::_narrow(ret);
1000 }

References pythonEntryName().

◆ setSqueezeStatus()

void YACS::ENGINE::PythonNode::setSqueezeStatus ( bool  sqStatus)
inline

Definition at line 111 of file PythonNode.hxx.

111 { _autoSqueeze=sqStatus; }

Referenced by main(), and setSqueezeStatusWithExceptions().

◆ setSqueezeStatusWithExceptions()

void PythonNode::setSqueezeStatusWithExceptions ( bool  sqStatus,
const std::vector< std::string > &  squeezeExceptions 
)

[EDF28562]

Parameters
insqueezeExceptions list on output port name excluded from the squeeze mecanism

Definition at line 861 of file PythonNode.cxx.

862 {
863  this->setSqueezeStatus(sqStatus);
864  this->_nonSqueezableOutputNodes = std::set<std::string>(squeezeExceptions.begin(), squeezeExceptions.end());
865 }
void setSqueezeStatus(bool sqStatus)
Definition: PythonNode.hxx:111

References _nonSqueezableOutputNodes, and setSqueezeStatus().

◆ shutdown()

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 917 of file PythonNode.cxx.

918 {
919  DEBTRACE("PythonNode::shutdown " << level);
920  if(_mode=="local")return;
921  if(_container)
922  {
924  _container->shutdown(level);
925  }
926 }
virtual void shutdown(int level)=0

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

◆ simpleClone()

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

Implements YACS::ENGINE::Node.

Definition at line 980 of file PythonNode.cxx.

981 {
982  return new PythonNode(*this,father);
983 }

References PythonNode().

◆ squeezeMemory()

void PythonNode::squeezeMemory ( )
protected

Definition at line 876 of file PythonNode.cxx.

877 {
878  for(auto p : _setOfInputPort)
879  {
880  PyDict_DelItemString(_context,p->getName().c_str());
881  InputPyPort *p2(static_cast<InputPyPort *>(p));
882  if(p2->canSafelySqueezeMemory())
883  p2->put(Py_None);
884  }
885  for(auto p : _setOfOutputPort)
886  {
887  if (!this->_nonSqueezableOutputNodes.empty() && this->_nonSqueezableOutputNodes.find(p->getName()) != this->_nonSqueezableOutputNodes.end())
888  continue;
889  PyDict_DelItemString(_context,p->getName().c_str());
890  OutputPyPort *p2(static_cast<OutputPyPort *>(p));
891  p2->putWithoutForward(Py_None);
892  }
893 }

References YACS::ENGINE::PythonEntry::_context, _nonSqueezableOutputNodes, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, YACS::ENGINE::InPort::canSafelySqueezeMemory(), YACS::ENGINE::ComposedNode::getName(), p, YACS::ENGINE::InputPyPort::put(), and YACS::ENGINE::OutputPyPort::putWithoutForward().

Referenced by executeLocal(), and squeezeMemorySafe().

◆ squeezeMemoryRemote()

void PythonNode::squeezeMemoryRemote ( )
protected

Definition at line 895 of file PythonNode.cxx.

896 {
897  for(auto p : _setOfInputPort)
898  {
899  InputPyPort *p2(static_cast<InputPyPort *>(p));
900  if(p2->canSafelySqueezeMemory())
901  p2->put(Py_None);
902  }
903  for(auto p : _setOfOutputPort)
904  {
905  if (!this->_nonSqueezableOutputNodes.empty() && this->_nonSqueezableOutputNodes.find(p->getName()) != this->_nonSqueezableOutputNodes.end())
906  continue;
907  OutputPyPort *p2(static_cast<OutputPyPort *>(p));
908  p2->putWithoutForward(Py_None);
909  }
910 }

References _nonSqueezableOutputNodes, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, YACS::ENGINE::InPort::canSafelySqueezeMemory(), YACS::ENGINE::ComposedNode::getName(), p, YACS::ENGINE::InputPyPort::put(), and YACS::ENGINE::OutputPyPort::putWithoutForward().

Referenced by executeRemote(), and squeezeMemorySafe().

◆ squeezeMemorySafe()

void PythonNode::squeezeMemorySafe ( )

Definition at line 867 of file PythonNode.cxx.

868 {
869  AutoGIL agil;
871  this->squeezeMemoryRemote();
872  else
873  this->squeezeMemory();
874 }

References YACS::ENGINE::InlineNode::_mode, REMOTE_NAME, squeezeMemory(), and squeezeMemoryRemote().

◆ typeName()

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

Reimplemented from YACS::ENGINE::InlineNode.

Definition at line 108 of file PythonNode.hxx.

108 { return "YACS__ENGINE__PythonNode"; }

Member Data Documentation

◆ _autoSqueeze

bool YACS::ENGINE::PythonNode::_autoSqueeze = false
protected

Definition at line 128 of file PythonNode.hxx.

Referenced by executeLocal(), and executeRemote().

◆ _nonSqueezableOutputNodes

std::set<std::string> YACS::ENGINE::PythonNode::_nonSqueezableOutputNodes
protected

list on output port name excluded from the squeeze mecanism

Definition at line 130 of file PythonNode.hxx.

Referenced by setSqueezeStatusWithExceptions(), squeezeMemory(), and squeezeMemoryRemote().

◆ _pynode

Engines::PyScriptNode_var YACS::ENGINE::PythonNode::_pynode
protected

◆ DPL_INFO_NAME

const char PythonNode::DPL_INFO_NAME ="my_dpl_localization"
static

Definition at line 126 of file PythonNode.hxx.

Referenced by applyDPLScope().

◆ IMPL_NAME

const char PythonNode::IMPL_NAME ="Python"
static

◆ KIND

const char PythonNode::KIND ="Python"
static

Definition at line 122 of file PythonNode.hxx.

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

◆ REMOTE_NAME

const char PythonNode::REMOTE_NAME ="remote"
static

◆ SCRIPT_FOR_SERIALIZATION

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

Definition at line 124 of file PythonNode.hxx.


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