Version: 9.16.0
YACS::ENGINE::PyFuncNode Class Reference

#include <PythonNode.hxx>

Inheritance diagram for YACS::ENGINE::PyFuncNode:
Collaboration diagram for YACS::ENGINE::PyFuncNode:

Public Member Functions

 PyFuncNode (const PyFuncNode &other, ComposedNode *father)
 
 PyFuncNode (const std::string &name)
 
virtual ~PyFuncNode ()
 
virtual void init (bool start=true)
 
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
 
std::string getContainerLog ()
 returns a string that contains the name of the container log file if it exists More...
 
PyFuncNodecloneNode (const std::string &name)
 Create a new node of same type with a given name. More...
 
virtual std::string typeName ()
 
- 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 ()
 
void accept (Visitor *visitor)
 
virtual ~InlineFuncNode ()
 
virtual std::string typeName ()
 
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 void accept (Visitor *visitor)
 
virtual ~InlineNode ()
 
virtual std::string typeName ()
 
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)
 
bool isDeployable () const
 
ComponentInstancegetComponent ()
 
const ComponentInstancegetComponent () const
 
ContainergetContainer ()
 
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
 
virtual void checkBasicConsistency () 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 std::string typeName ()
 
virtual void edUpdateState ()
 update the status of the node More...
 
virtual void ensureLoading ()
 Put this node into TOLOAD state when possible. More...
 
int getMaxLevelOfParallelism () const
 
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 load ()
 
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...
 
void accept (Visitor *visitor)
 
virtual void addDatastreamPortToInitMultiService (const std::string &port_name, int number)
 
- Public Member Functions inherited from YACS::ENGINE::Node
virtual ~Node ()
 
virtual void init (bool start=true)
 
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 getState () const
 
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 exUpdateState ()
 Update the node state. 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...
 
virtual void getReadyTasks (std::vector< Task * > &tasks)=0
 
virtual std::list< ElementaryNode * > getRecursiveConstituents () const =0
 
virtual std::list< ProgressWeightgetProgressWeight () const =0
 
virtual int getNumberOfInputPorts () const =0
 
virtual int getNumberOfOutputPorts () const =0
 
std::list< InPort * > getSetOfInPort () const
 
std::list< OutPort * > getSetOfOutPort () const
 
virtual std::list< InputPort * > getSetOfInputPort () const =0
 
virtual std::list< OutputPort * > getSetOfOutputPort () const =0
 
virtual std::list< InputPort * > getLocalInputPorts () const =0
 
virtual std::list< OutputPort * > getLocalOutputPorts () const =0
 
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...
 
virtual std::string getInPortName (const InPort *) const =0
 
virtual std::string getOutPortName (const OutPort *) const =0
 
virtual std::list< InputDataStreamPort * > getSetOfInputDataStreamPort () const =0
 
virtual std::list< OutputDataStreamPort * > getSetOfOutputDataStreamPort () const =0
 
InPortgetInPort (const std::string &name) const
 
InPropertyPortgetInPropertyPort () const
 
virtual OutPortgetOutPort (const std::string &name) const
 
virtual std::set< OutPort * > getAllOutPortsLeavingCurrentScope () const =0
 
virtual std::set< InPort * > getAllInPortsComingFromOutsideOfCurrentScope () const =0
 
virtual std::vector< std::pair< OutPort *, InPort * > > getSetOfLinksLeavingCurrentScope () const =0
 
virtual std::vector< std::pair< InPort *, OutPort * > > getSetOfLinksComingInCurrentScope () const =0
 
virtual InputPortgetInputPort (const std::string &name) const
 
virtual OutputPortgetOutputPort (const std::string &name) const =0
 
virtual InputDataStreamPortgetInputDataStreamPort (const std::string &name) const =0
 
virtual OutputDataStreamPortgetOutputDataStreamPort (const std::string &name) const =0
 
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 NodegetChildByName (const std::string &name) const =0
 
virtual ProcgetProc ()
 
virtual const ProcgetProc () const
 
virtual void accept (Visitor *visitor)=0
 
virtual int getMaxLevelOfParallelism () const =0
 
virtual void getWeightRegardingDPL (ComplexWeight *weight)=0
 
virtual void partitionRegardingDPL (const PartDefinition *pd, std::map< ComposedNode *, YACS::BASES::AutoRefCnt< PartDefinition > > &zeMap)=0
 
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 typeName ()
 
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 void edUpdateState ()
 update the status of the node 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 ensureLoading ()
 Put this node into TOLOAD state when possible. More...
 
virtual void getCoupledNodes (std::set< Task * > &coupledNodes)
 
virtual void cleanNodes ()
 Clean the node in case of not clean exit. More...
 
- Public Member Functions inherited from YACS::ENGINE::Task
virtual void begin ()=0
 
virtual bool isReady ()=0
 
virtual void execute ()=0
 
virtual void load ()=0
 
virtual void loaded ()=0
 
virtual void connected ()=0
 
virtual void initService ()=0
 
virtual void connectService ()=0
 
virtual void disconnectService ()=0
 
virtual void getCoupledTasks (std::set< Task * > &coupledSet)=0
 
virtual bool isDeployable () const =0
 
virtual ComponentInstancegetComponent ()=0
 
virtual const ComponentInstancegetComponent () const =0
 
virtual ContainergetContainer ()=0
 
virtual YACS::StatesForNode getState () const =0
 
virtual void finished ()=0
 
virtual void aborted ()=0
 
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 SCRIPT_FOR_SERIALIZATION []
 
- 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
 
- 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 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...
 
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 performDuplicationOfPlacement (const Node &other)=0
 performs a duplication of placement using clone method of containers and components. clone behaviour is driven by attachOnCloning attribute. More...
 
virtual void performShallowDuplicationOfPlacement (const Node &other)=0
 performs a also duplication of placement but here containers and components are not copied at all whatever the value of attachedOnCloning. More...
 
virtual NodesimpleClone (ComposedNode *father, bool editionOnly=true) const =0
 
virtual void exForwardFailed ()
 
virtual void exForwardFinished ()
 
virtual void edDisconnectAllLinksWithMe ()
 
- Protected Member Functions inherited from YACS::ENGINE::PythonEntry
 PythonEntry ()
 
 ~PythonEntry ()
 
virtual void assignRemotePyInterpretor (Engines::PyNodeBase_var remoteInterp)=0
 
virtual Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny (Engines::Container_ptr objContainer) const =0
 returns (if any) an object, you have to deal with (UnRegister) More...
 
virtual void createRemoteAdaptedPyInterpretor (Engines::Container_ptr objContainer)=0
 returns an object, you have to deal with (UnRegister) More...
 
virtual Engines::PyNodeBase_var getRemoteInterpreterHandle ()=0
 
virtual const char * getSerializationScript () const =0
 
void commonRemoteLoad (InlineNode *reqNode)
 
void loadRemoteContainer (InlineNode *reqNode)
 
Engines::Container_var loadPythonAdapter (InlineNode *reqNode, bool &isInitializeRequested)
 
void loadRemoteContext (InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested)
 
virtual bool hasImposedResource () const
 

Protected Attributes

PyObject * _pyfunc
 
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
 
- Protected Attributes inherited from YACS::ENGINE::PythonEntry
PyObject * _context
 
PyObject * _pyfuncSer
 
PyObject * _pyfuncUnser
 
PyObject * _pyfuncSimpleSer
 
std::string _imposedResource
 
std::string _imposedContainer
 

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)
 
- 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)
 
- 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 134 of file PythonNode.hxx.

Constructor & Destructor Documentation

◆ PyFuncNode() [1/2]

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

Definition at line 1096 of file PythonNode.cxx.

1096 :InlineFuncNode(other,father),_pyfunc(0)
1097{
1099 {
1100 AutoGIL agil;
1101 _context=PyDict_New();
1102 DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
1103 if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
1104 {
1105 stringstream msg;
1106 msg << "Not possible to set builtins" << __FILE__ << ":" << __LINE__;
1107 _errorDetails=msg.str();
1108 throw Exception(msg.str());
1109 }
1110 }
1111}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
InlineFuncNode(const InlineFuncNode &other, ComposedNode *father)
Definition: InlineNode.hxx:95
std::string _implementation
Definition: Node.hxx:97
std::string _errorDetails
Definition: Node.hxx:93
static const char IMPL_NAME[]
Definition: PythonNode.hxx:123
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()

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

Referenced by cloneNode(), and simpleClone().

◆ PyFuncNode() [2/2]

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

Definition at line 1113 of file PythonNode.cxx.

1113 : InlineFuncNode(name),_pyfunc(0)
1114{
1115
1117 DEBTRACE( "PyFuncNode::PyFuncNode " << name );
1118 {
1119 AutoGIL agil;
1120 _context=PyDict_New();
1121 DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
1122 if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
1123 {
1124 stringstream msg;
1125 msg << "Not possible to set builtins" << __FILE__ << ":" << __LINE__;
1126 _errorDetails=msg.str();
1127 throw Exception(msg.str());
1128 }
1129 }
1130}

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

◆ ~PyFuncNode()

PyFuncNode::~PyFuncNode ( )
virtual

Definition at line 1132 of file PythonNode.cxx.

1133{
1134 if(!CORBA::is_nil(_pynode))
1135 {
1136 _pynode->UnRegister();
1137 }
1138}
Engines::PyNode_var _pynode
Definition: PythonNode.hxx:168

References _pynode.

Member Function Documentation

◆ assignRemotePyInterpretor()

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

Implements YACS::ENGINE::PythonEntry.

Definition at line 1596 of file PythonNode.cxx.

1597{
1598 if(!CORBA::is_nil(_pynode))
1599 {
1600 Engines::PyNode_var tmpp(Engines::PyNode::_narrow(remoteInterp));
1601 if(_pynode->_is_equivalent(tmpp))
1602 return ;
1603 }
1604 if(!CORBA::is_nil(_pynode))
1605 _pynode->UnRegister();
1606 _pynode=Engines::PyNode::_narrow(remoteInterp);
1607}

References _pynode.

◆ canAcceptImposedResource()

bool PyFuncNode::canAcceptImposedResource ( )
overridevirtual

Reimplemented from YACS::ENGINE::Task.

Definition at line 1662 of file PythonNode.cxx.

1663{
1664 return _container != nullptr && _container->canAcceptImposedResource();
1665}
virtual bool canAcceptImposedResource()
Definition: Container.cxx:59

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

◆ checkBasicConsistency()

void PyFuncNode::checkBasicConsistency ( ) const
virtual

Reimplemented from YACS::ENGINE::InlineFuncNode.

Definition at line 1154 of file PythonNode.cxx.

1155{
1156 DEBTRACE("checkBasicConsistency");
1158 {
1159 AutoGIL agil;
1160 PyObject* res;
1161 res=Py_CompileString(_script.c_str(),getName().c_str(),Py_file_input);
1162 if(res == NULL)
1163 {
1164 std::string error="";
1165 PyObject* new_stderr = newPyStdOut(error);
1166 PySys_SetObject((char*)"stderr", new_stderr);
1167 PyErr_Print();
1168 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1169 Py_DECREF(new_stderr);
1170 throw Exception(error);
1171 }
1172 else
1173 Py_XDECREF(res);
1174 }
1175}
virtual void checkBasicConsistency() const
Definition: InlineNode.cxx:75
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::InlineFuncNode::checkBasicConsistency(), DEBTRACE, YACS::ENGINE::Node::getName(), and YACS::ENGINE::newPyStdOut().

◆ cloneNode()

PyFuncNode * PyFuncNode::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 1615 of file PythonNode.cxx.

1616{
1617 PyFuncNode* n=new PyFuncNode(name);
1618 n->setScript(_script);
1619 n->setFname(_fname);
1620 list<InputPort *>::iterator iter;
1621 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
1622 {
1623 InputPyPort *p=(InputPyPort *)*iter;
1624 n->edAddInputPort(p->getName(),p->edGetType());
1625 }
1626 list<OutputPort *>::iterator iter2;
1627 for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
1628 {
1629 OutputPyPort *p=(OutputPyPort *)*iter2;
1630 n->edAddOutputPort(p->getName(),p->edGetType());
1631 }
1632 return n;
1633}
std::string getName() const
std::list< InputPort * > _setOfInputPort
std::list< OutputPort * > _setOfOutputPort
Class for Python Ports.
Definition: PythonPorts.hxx:74
PyFuncNode(const PyFuncNode &other, ComposedNode *father)
Proc * p
Definition: driver.cxx:216

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

◆ createRemoteAdaptedPyInterpretor()

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

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

Implements YACS::ENGINE::PythonEntry.

Definition at line 1579 of file PythonNode.cxx.

1580{
1581 if(!CORBA::is_nil(_pynode))
1582 _pynode->UnRegister();
1583 _pynode=objContainer->createPyNode(getName().c_str(),getScript().c_str());
1584}
virtual std::string getScript()
Definition: InlineNode.hxx:51

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

◆ execute()

void PyFuncNode::execute ( )
virtual

Implements YACS::ENGINE::Task.

Definition at line 1263 of file PythonNode.cxx.

1264{
1266 executeRemote();
1267 else
1268 executeLocal();
1269}
virtual void executeRemote()
virtual void executeLocal()
static const char REMOTE_NAME[]
Definition: PythonNode.hxx:125

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

◆ executeLocal()

void PyFuncNode::executeLocal ( )
virtual

Definition at line 1458 of file PythonNode.cxx.

1459{
1460 DEBTRACE( "++++++++++++++ PyFuncNode::execute: " << getName() << " ++++++++++++++++++++" );
1461
1462 int pos=0;
1463 PyObject* ob;
1464 if(!_pyfunc)throw Exception("PyFuncNode badly loaded");
1465 {
1466 AutoGIL agil;
1467 DEBTRACE( "---------------PyFuncNode::inputs---------------" );
1468 PyObject* args = PyTuple_New(getNumberOfInputPorts()) ;
1469 list<InputPort *>::iterator iter2;
1470 for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
1471 {
1472 InputPyPort *p=(InputPyPort *)*iter2;
1473 DEBTRACE( "port name: " << p->getName() );
1474 DEBTRACE( "port kind: " << p->edGetType()->kind() );
1475 ob=p->getPyObj();
1476#ifdef _DEVDEBUG_
1477 PyObject_Print(ob,stderr,Py_PRINT_RAW);
1478 cerr << endl;
1479#endif
1480 DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1481 Py_INCREF(ob);
1482 PyTuple_SetItem(args,pos,ob);
1483 DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1484 pos++;
1485 }
1486 DEBTRACE( "---------------End PyFuncNode::inputs---------------" );
1487
1488 DEBTRACE( "----------------PyFuncNode::calculation---------------" );
1489#ifdef _DEVDEBUG_
1490 PyObject_Print(_pyfunc,stderr,Py_PRINT_RAW);
1491 cerr << endl;
1492 PyObject_Print(args,stderr,Py_PRINT_RAW);
1493 cerr << endl;
1494#endif
1495 DEBTRACE( "_pyfunc refcnt: " << _pyfunc->ob_refcnt );
1496 PyObject* result = PyObject_CallObject( _pyfunc , args ) ;
1497 DEBTRACE( "_pyfunc refcnt: " << _pyfunc->ob_refcnt );
1498 Py_DECREF(args);
1499 fflush(stdout);
1500 fflush(stderr);
1501 if(result == NULL)
1502 {
1503 _errorDetails="";
1504 PyObject* new_stderr = newPyStdOut(_errorDetails);
1505 PySys_SetObject((char*)"stderr", new_stderr);
1506 std::ostringstream stream;
1507 stream << "/tmp/PythonNode_";
1508 stream << getpid();
1509 ofstream errorfile(stream.str().c_str());
1510 if (errorfile.is_open())
1511 {
1512 errorfile << _script;
1513 errorfile.close();
1514 }
1515 PyErr_Print();
1516 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1517 Py_DECREF(new_stderr);
1518 throw Exception("Error during execution");
1519 }
1520 DEBTRACE( "----------------End PyFuncNode::calculation---------------" );
1521
1522 DEBTRACE( "-----------------PyFuncNode::outputs-----------------" );
1523 int nres=1;
1524 if(result == Py_None)
1525 nres=0;
1526 else if(PyTuple_Check(result))
1527 nres=PyTuple_Size(result);
1528
1529 if(getNumberOfOutputPorts() != nres)
1530 {
1531 std::string msg="Number of output arguments : Mismatch between definition and execution";
1532 Py_DECREF(result);
1533 _errorDetails=msg;
1534 throw Exception(msg);
1535 }
1536
1537 pos=0;
1538#ifdef _DEVDEBUG_
1539 PyObject_Print(result,stderr,Py_PRINT_RAW);
1540 cerr << endl;
1541#endif
1542 list<OutputPort *>::iterator iter;
1543 try
1544 {
1545 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
1546 {
1547 OutputPyPort *p=(OutputPyPort *)*iter;
1548 DEBTRACE( "port name: " << p->getName() );
1549 DEBTRACE( "port kind: " << p->edGetType()->kind() );
1550 DEBTRACE( "port pos : " << pos );
1551 if(PyTuple_Check(result))ob=PyTuple_GetItem(result,pos) ;
1552 else ob=result;
1553 DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1554#ifdef _DEVDEBUG_
1555 PyObject_Print(ob,stderr,Py_PRINT_RAW);
1556 cerr << endl;
1557#endif
1558 p->put(ob);
1559 pos++;
1560 }
1561 }
1562 catch(ConversionException& ex)
1563 {
1564 Py_DECREF(result);
1565 _errorDetails=ex.what();
1566 throw;
1567 }
1568 DEBTRACE( "-----------------End PyFuncNode::outputs-----------------" );
1569 Py_DECREF(result);
1570 }
1571 DEBTRACE( "++++++++++++++ End PyFuncNode::execute: " << getName() << " ++++++++++++++++++++" );
1572}

References YACS::ENGINE::Node::_errorDetails, _pyfunc, YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::_setOfInputPort, YACS::ENGINE::ElementaryNode::_setOfOutputPort, driver_internal::args, DEBTRACE, testCppPluginInvokation::ex, YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::ElementaryNode::getNumberOfInputPorts(), YACS::ENGINE::ElementaryNode::getNumberOfOutputPorts(), YACS::ENGINE::newPyStdOut(), and p.

Referenced by execute().

◆ executeRemote()

void PyFuncNode::executeRemote ( )
virtual

Definition at line 1271 of file PythonNode.cxx.

1272{
1273 DEBTRACE( "++++++++++++++ PyFuncNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
1274 if(!_pyfuncSer)
1275 throw Exception("DistributedPythonNode badly loaded");
1276 //
1277 if(dynamic_cast<HomogeneousPoolContainer *>(getContainer()))
1278 {
1279 bool dummy;
1280 loadPythonAdapter(this,dummy);
1281 _pynode->executeAnotherPieceOfCode(getScript().c_str());
1282 }
1283 //
1284 Engines::pickledArgs_var serializationInputCorba(new Engines::pickledArgs);;
1285 {
1286#if PY_VERSION_HEX < 0x03070000
1287 std::unique_lock<std::mutex> lock(data_mutex);
1288#endif
1289 AutoGIL agil;
1290 PyObject *ob(0);
1291 //===========================================================================
1292 // Get inputs in input ports, build a Python tuple and pickle it
1293 //===========================================================================
1294 PyObject *args(PyTuple_New(getNumberOfInputPorts()));
1295 int pos(0);
1296 for(std::list<InputPort *>::iterator iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++,pos++)
1297 {
1298 InputPyPort *p=(InputPyPort *)*iter2;
1299 ob=p->getPyObj();
1300 Py_INCREF(ob);
1301 PyTuple_SetItem(args,pos,ob);
1302 }
1303#ifdef _DEVDEBUG_
1304 PyObject_Print(args,stderr,Py_PRINT_RAW);
1305 std::cerr << endl;
1306#endif
1307 PyObject *serializationInput=PyObject_CallObject(_pyfuncSer,args);
1308 Py_DECREF(args);
1309 //The pickled string may contain NULL characters so use PyString_AsStringAndSize
1310 char *serializationInputC(0);
1311 Py_ssize_t len;
1312 if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
1313 throw Exception("DistributedPythonNode problem in python pickle");
1314
1315 serializationInputCorba->length(len);
1316 for(int i=0; i < len ; i++)
1317 serializationInputCorba[i]=serializationInputC[i];
1318 Py_DECREF(serializationInput);
1319 }
1320
1321 //===========================================================================
1322 // Execute in remote Python node
1323 //===========================================================================
1324 DEBTRACE( "-----------------starting remote python invocation-----------------" );
1325 Engines::pickledArgs_var resultCorba;
1326 try
1327 {
1328 resultCorba=_pynode->execute(getFname().c_str(),serializationInputCorba);
1329 }
1330 catch( const SALOME::SALOME_Exception& ex )
1331 {
1332 std::string msg="Exception on remote python invocation";
1333 msg += '\n';
1334 msg += ex.details.text.in();
1335 _errorDetails=msg;
1336 throw Exception(msg);
1337 }
1338 catch(CORBA::COMM_FAILURE& ex)
1339 {
1340 std::ostringstream msg;
1341 msg << "Exception on remote python invocation." << std::endl ;
1342 msg << "Caught system exception COMM_FAILURE -- unable to contact the "
1343 << "object." << std::endl;
1344 _errorDetails=msg.str();
1345 throw Exception(msg.str());
1346 }
1347 catch(CORBA::SystemException& ex)
1348 {
1349 std::ostringstream msg;
1350 msg << "Exception on remote python invocation." << std::endl ;
1351 msg << "Caught a CORBA::SystemException." ;
1352 CORBA::Any tmp;
1353 tmp <<= ex;
1354 CORBA::TypeCode_var tc = tmp.type();
1355 const char *p = tc->name();
1356 if ( *p != '\0' )
1357 msg <<p;
1358 else
1359 msg << tc->id();
1360 msg << std::endl;
1361 _errorDetails=msg.str();
1362 throw Exception(msg.str());
1363 }
1364 catch(CORBA::Exception& ex)
1365 {
1366 std::ostringstream msg;
1367 msg << "Exception on remote python invocation." << std::endl ;
1368 msg << "Caught CORBA::Exception. " ;
1369 CORBA::Any tmp;
1370 tmp <<= ex;
1371 CORBA::TypeCode_var tc = tmp.type();
1372 const char *p = tc->name();
1373 if ( *p != '\0' )
1374 msg <<p;
1375 else
1376 msg << tc->id();
1377 msg << std::endl;
1378 _errorDetails=msg.str();
1379 throw Exception(msg.str());
1380 }
1381 catch(omniORB::fatalException& fe)
1382 {
1383 std::ostringstream msg;
1384 msg << "Exception on remote python invocation." << std::endl ;
1385 msg << "Caught omniORB::fatalException:" << std::endl;
1386 msg << " file: " << fe.file() << std::endl;
1387 msg << " line: " << fe.line() << std::endl;
1388 msg << " mesg: " << fe.errmsg() << std::endl;
1389 _errorDetails=msg.str();
1390 throw Exception(msg.str());
1391 }
1392 DEBTRACE( "-----------------end of remote python invocation-----------------" );
1393 //===========================================================================
1394 // Get results, unpickle and put them in output ports
1395 //===========================================================================
1396 char *resultCorbaC=new char[resultCorba->length()+1];
1397 resultCorbaC[resultCorba->length()]='\0';
1398 for(int i=0;i<resultCorba->length();i++)
1399 resultCorbaC[i]=resultCorba[i];
1400
1401 {
1402#if PY_VERSION_HEX < 0x03070000
1403 std::unique_lock<std::mutex> lock(data_mutex);
1404#endif
1405 AutoGIL agil;
1406
1407 PyObject *resultPython(PyBytes_FromStringAndSize(resultCorbaC,resultCorba->length()));
1408 delete [] resultCorbaC;
1409 PyObject *args(PyTuple_New(1)),*ob(0);
1410 PyTuple_SetItem(args,0,resultPython);
1411 PyObject *finalResult=PyObject_CallObject(_pyfuncUnser,args);
1412 Py_DECREF(args);
1413
1414 DEBTRACE( "-----------------PythonNode::outputs-----------------" );
1415 int nres=1;
1416 if(finalResult == Py_None)
1417 nres=0;
1418 else if(PyTuple_Check(finalResult))
1419 nres=PyTuple_Size(finalResult);
1420
1421 if(getNumberOfOutputPorts() != nres)
1422 {
1423 std::string msg="Number of output arguments : Mismatch between definition and execution";
1424 Py_DECREF(finalResult);
1425 _errorDetails=msg;
1426 throw Exception(msg);
1427 }
1428
1429 try
1430 {
1431 int pos(0);
1432 for(std::list<OutputPort *>::iterator iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++, pos++)
1433 {
1434 OutputPyPort *p=(OutputPyPort *)*iter;
1435 DEBTRACE( "port name: " << p->getName() );
1436 DEBTRACE( "port kind: " << p->edGetType()->kind() );
1437 DEBTRACE( "port pos : " << pos );
1438 if(PyTuple_Check(finalResult))
1439 ob=PyTuple_GetItem(finalResult,pos) ;
1440 else
1441 ob=finalResult;
1442 DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1443 p->put(ob);
1444 }
1445 Py_DECREF(finalResult);
1446 }
1447 catch(ConversionException& ex)
1448 {
1449 Py_DECREF(finalResult);
1450 _errorDetails=ex.what();
1451 throw;
1452 }
1453 }
1454
1455 DEBTRACE( "++++++++++++++ ENDOF PyFuncNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
1456}
int Py_ssize_t
Definition: PythonNode.cxx:45
static std::mutex data_mutex
Definition: PythonNode.cxx:90
virtual std::string getFname()
Definition: InlineNode.hxx:101
virtual Container * getContainer()
Definition: InlineNode.cxx:100
Engines::Container_var loadPythonAdapter(InlineNode *reqNode, bool &isInitializeRequested)
Definition: PythonNode.cxx:165

References 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, testCppPluginInvokation::ex, YACS::ENGINE::InlineNode::getContainer(), YACS::ENGINE::InlineFuncNode::getFname(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::ElementaryNode::getNumberOfInputPorts(), YACS::ENGINE::ElementaryNode::getNumberOfOutputPorts(), YACS::ENGINE::InlineNode::getScript(), yacsorb.CORBAEngineTest::i, YACS::ENGINE::PythonEntry::loadPythonAdapter(), and p.

Referenced by execute().

◆ getContainerLog()

std::string PyFuncNode::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 1635 of file PythonNode.cxx.

1636{
1638}
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 PyFuncNode::getRemoteInterpreterHandle ( )
protectedvirtual

Implements YACS::ENGINE::PythonEntry.

Definition at line 1609 of file PythonNode.cxx.

1610{
1611 return Engines::PyNodeBase::_narrow(_pynode);
1612}

References _pynode.

◆ getSerializationScript()

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

Implements YACS::ENGINE::PythonEntry.

Definition at line 143 of file PythonNode.hxx.

143{ return SCRIPT_FOR_SERIALIZATION; }
static const char SCRIPT_FOR_SERIALIZATION[]
Definition: PythonNode.hxx:165

◆ hasImposedResource()

bool PyFuncNode::hasImposedResource ( ) const
overridevirtual

Reimplemented from YACS::ENGINE::PythonEntry.

Definition at line 1667 of file PythonNode.cxx.

1668{
1670}
virtual bool hasImposedResource() const
Definition: PythonNode.cxx:326

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

◆ imposeResource()

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

Reimplemented from YACS::ENGINE::Task.

Definition at line 1652 of file PythonNode.cxx.

1654{
1655 if(!resource_name.empty() && !container_name.empty())
1656 {
1657 _imposedResource = resource_name;
1658 _imposedContainer = container_name;
1659 }
1660}
std::string _imposedResource
Definition: PythonNode.hxx:69
std::string _imposedContainer
Definition: PythonNode.hxx:70

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

◆ init()

void PyFuncNode::init ( bool  start = true)
virtual

initialisation of all input and output ports and gates, for execution

Reimplemented from YACS::ENGINE::ElementaryNode.

Definition at line 1140 of file PythonNode.cxx.

1141{
1143 if(_state == YACS::DISABLED)
1144 {
1145 exDisabledState(); // to refresh propagation of DISABLED state
1146 return ;
1147 }
1148 if(start) //complete initialization
1150 else if(_state > YACS::LOADED)// WARNING FuncNode has internal vars (CEA usecase) ! Partial initialization (inside a loop). Exclusivity of funcNode.
1152}
void initCommonPartWithoutStateManagement(bool start)
void setState(YACS::StatesForNode theState)
Sets the given state for node.
Definition: Node.cxx:652
virtual void exDisabledState()
Notify this node that it has been disabled.
Definition: Node.cxx:232
YACS::StatesForNode _state
Definition: Node.hxx:91
@ LOADED
Definition: define.hxx:39
@ READY
Definition: define.hxx:37
@ DISABLED
Definition: define.hxx:50
@ TORECONNECT
Definition: define.hxx:48

References YACS::ENGINE::Node::_state, YACS::DISABLED, YACS::ENGINE::Node::exDisabledState(), YACS::ENGINE::ElementaryNode::initCommonPartWithoutStateManagement(), YACS::LOADED, YACS::READY, YACS::ENGINE::Node::setState(), and YACS::TORECONNECT.

◆ load()

void PyFuncNode::load ( )
virtual

Reimplemented from YACS::ENGINE::ElementaryNode.

Definition at line 1177 of file PythonNode.cxx.

1178{
1179 DEBTRACE( "---------------PyfuncNode::load function---------------" );
1181 loadRemote();
1182 else
1183 loadLocal();
1184}
virtual void loadLocal()
virtual void loadRemote()

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

◆ loadLocal()

void PyFuncNode::loadLocal ( )
virtual

Definition at line 1191 of file PythonNode.cxx.

1192{
1193 DEBTRACE( "---------------PyFuncNode::load function " << getName() << " ---------------" );
1194 DEBTRACE( _script );
1195
1196#ifdef _DEVDEBUG_
1197 list<OutputPort *>::iterator iter;
1198 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
1199 {
1200 OutputPyPort *p=(OutputPyPort *)*iter;
1201 DEBTRACE( "port name: " << p->getName() );
1202 DEBTRACE( "port kind: " << p->edGetType()->kind() );
1203 }
1204#endif
1205
1206 {
1207 AutoGIL agil;
1208 DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
1209
1210 std::ostringstream stream;
1211 stream << "/tmp/PythonNode_";
1212 stream << getpid();
1213
1214 PyObject* code=Py_CompileString(_script.c_str(), stream.str().c_str(), Py_file_input);
1215 if(code == NULL)
1216 {
1217 _errorDetails="";
1218 PyObject* new_stderr = newPyStdOut(_errorDetails);
1219 PySys_SetObject((char*)"stderr", new_stderr);
1220 PyErr_Print();
1221 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1222 Py_DECREF(new_stderr);
1223 throw Exception("Error during execution");
1224 }
1225 PyObject *res = PyEval_EvalCode( code, _context, _context);
1226 Py_DECREF(code);
1227 Py_XDECREF(res);
1228
1229 DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
1230 if(PyErr_Occurred ())
1231 {
1232 _errorDetails="";
1233 PyObject* new_stderr = newPyStdOut(_errorDetails);
1234 PySys_SetObject((char*)"stderr", new_stderr);
1235 ofstream errorfile(stream.str().c_str());
1236 if (errorfile.is_open())
1237 {
1238 errorfile << _script;
1239 errorfile.close();
1240 }
1241 PyErr_Print();
1242 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1243 Py_DECREF(new_stderr);
1244 throw Exception("Error during execution");
1245 return;
1246 }
1247 _pyfunc=PyDict_GetItemString(_context,_fname.c_str());
1248 DEBTRACE( "_pyfunc refcnt: " << _pyfunc->ob_refcnt );
1249 if(_pyfunc == NULL)
1250 {
1251 _errorDetails="";
1252 PyObject* new_stderr = newPyStdOut(_errorDetails);
1253 PySys_SetObject((char*)"stderr", new_stderr);
1254 PyErr_Print();
1255 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1256 Py_DECREF(new_stderr);
1257 throw Exception("Error during execution");
1258 }
1259 DEBTRACE( "---------------End PyFuncNode::load function---------------" );
1260 }
1261}

References YACS::ENGINE::PythonEntry::_context, YACS::ENGINE::Node::_errorDetails, YACS::ENGINE::InlineFuncNode::_fname, _pyfunc, YACS::ENGINE::InlineNode::_script, YACS::ENGINE::ElementaryNode::_setOfOutputPort, DEBTRACE, YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getName(), YACS::ENGINE::newPyStdOut(), and p.

Referenced by load().

◆ loadRemote()

void PyFuncNode::loadRemote ( )
virtual

Definition at line 1186 of file PythonNode.cxx.

1187{
1188 commonRemoteLoad(this);
1189}
void commonRemoteLoad(InlineNode *reqNode)
Definition: PythonNode.cxx:318

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

Referenced by load().

◆ retrieveDftRemotePyInterpretorIfAny()

Engines::PyNodeBase_var PyFuncNode::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 1586 of file PythonNode.cxx.

1587{
1588 Engines::PyNode_var ret(objContainer->getDefaultPyNode(getName().c_str()));
1589 if(!CORBA::is_nil(ret))
1590 {
1591 ret->Register();
1592 }
1593 return Engines::PyNodeBase::_narrow(ret);
1594}

References YACS::ENGINE::Node::getName().

◆ shutdown()

void PyFuncNode::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 1640 of file PythonNode.cxx.

1641{
1642 DEBTRACE("PyFuncNode::shutdown " << level);
1643 if(_mode=="local")return;
1644 if(_container)
1645 {
1646 if(!CORBA::is_nil(_pynode)) _pynode->UnRegister();
1647 _pynode=Engines::PyNode::_nil();
1648 _container->shutdown(level);
1649 }
1650}
virtual void shutdown(int level)=0

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

◆ simpleClone()

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

Implements YACS::ENGINE::Node.

Definition at line 1574 of file PythonNode.cxx.

1575{
1576 return new PyFuncNode(*this,father);
1577}

References PyFuncNode().

◆ typeName()

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

Reimplemented from YACS::ENGINE::InlineFuncNode.

Definition at line 163 of file PythonNode.hxx.

163{ return "YACS__ENGINE__PyFuncNode"; }

Member Data Documentation

◆ _pyfunc

PyObject* YACS::ENGINE::PyFuncNode::_pyfunc
protected

Definition at line 167 of file PythonNode.hxx.

Referenced by executeLocal(), and loadLocal().

◆ _pynode

Engines::PyNode_var YACS::ENGINE::PyFuncNode::_pynode
protected

◆ SCRIPT_FOR_SERIALIZATION

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

Definition at line 165 of file PythonNode.hxx.


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