24 #include "PythonCppUtils.hxx"
30 #include "ReceiverFactory.hxx"
31 #include "SenderByteImpl.hxx"
41 #define getpid _getpid
44 #if PY_VERSION_HEX < 0x02050000
55 "def pickleForVarSimplePyth2009(val):\n"
56 " return pickle.dumps(val,-1)\n"
65 "def pickleForDistPyth2009(kws):\n"
66 " return pickle.dumps(((),kws),-1)\n"
68 "def unPickleForDistPyth2009(st):\n"
69 " args=pickle.loads(st)\n"
77 "def pickleForDistPyth2009(*args,**kws):\n"
78 " return pickle.dumps((args,kws),-1)\n"
80 "def unPickleForDistPyth2009(st):\n"
81 " args=pickle.loads(st)\n"
85 "BigObjectOnDiskBase = SALOME_PyNode.BigObjectOnDiskBase\n";
88 #if PY_VERSION_HEX < 0x03070000
108 DEBTRACE(
"---------------PythonEntry::CommonRemoteLoad function---------------" );
110 bool isContAlreadyStarted(
false);
120 if(!isContAlreadyStarted)
121 container->
start(reqNode);
132 std::string what(
"PythonEntry::CommonRemoteLoad : a load operation requested on \"");
133 what+=reqNode->
getName(); what+=
"\" with no container specified.";
141 isStandardCont =
false;
143 Engines::Container_var objContainer(Engines::Container::_nil());
150 isStandardCont =
true;
153 else if(containerCast1)
156 objContainer=tmpCont->getContainerPtr(reqNode);
159 throw YACS::Exception(
"Unrecognized type of container ! Salome one is expected for PythonNode/PyFuncNode !");
160 if(CORBA::is_nil(objContainer))
161 throw YACS::Exception(
"Container corba pointer is NULL for PythonNode !");
167 bool isStandardCont(
true);
168 Engines::Container_var objContainer(
GetContainerObj(reqNode,isStandardCont));
169 isInitializeRequested=
false;
173 if(CORBA::is_nil(dftPyScript))
175 isInitializeRequested=!isStandardCont;
181 catch(
const SALOME::SALOME_Exception&
ex )
183 std::string msg=
"Exception on remote python node creation ";
185 msg +=
ex.details.text.in();
190 if(CORBA::is_nil(pynode))
191 throw Exception(
"In PythonNode the ref in NULL ! ");
201 #if PY_VERSION_HEX < 0x03070000
202 std::unique_lock<std::mutex> lock(
data_mutex);
208 if(res == NULL || res2==NULL)
210 std::string errorDetails;
213 PySys_SetObject((
char*)
"stderr", new_stderr);
215 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
216 Py_DECREF(new_stderr);
219 Py_DECREF(res); Py_DECREF(res2);
231 std::string errorDetails;
234 PySys_SetObject((
char*)
"stderr", new_stderr);
236 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
237 Py_DECREF(new_stderr);
242 std::string errorDetails;
245 PySys_SetObject((
char*)
"stderr", new_stderr);
247 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
248 Py_DECREF(new_stderr);
253 std::string errorDetails;
256 PySys_SetObject((
char*)
"stderr", new_stderr);
258 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
259 Py_DECREF(new_stderr);
263 if(isInitializeRequested)
268 if(!zeInitScriptKey.empty())
269 pynode->executeAnotherPieceOfCode(zeInitScriptKey.c_str());
271 catch(
const SALOME::SALOME_Exception&
ex )
273 std::string msg=
"Exception on PythonNode::loadRemote python invocation of initializisation py script !";
275 msg +=
ex.details.text.in();
279 DEBTRACE(
"---------------End PyNode::loadRemote function---------------" );
295 Engines::Container_var objContainer(containerCast->
getContainerPtr(askingTask));
296 CORBA::String_var logname = objContainer->logfilename();
299 std::string::size_type pos = msg.find(
":");
300 msg=msg.substr(pos+1);
302 else if(objContainer2)
304 msg=
"Remote PythonNode is on HP Container : no log because no info of the location by definition of HP Container !";
308 msg=
"Not implemented yet for container log for that type of container !";
313 msg =
"Container no longer reachable";
321 bool isInitializeRequested;
322 Engines::Container_var objContainer(
loadPythonAdapter(reqNode,isInitializeRequested));
341 if( PyList_Check( ob ) )
343 auto sz = PyList_Size( ob );
344 for(
auto i = 0 ;
i < sz ; ++
i )
346 PyObject *elt = PyList_GetItem( ob,
i );
361 AutoPyRef unlinkOnDestructor = PyObject_GetAttrString(ob,
"getDestroyStatus");
362 AutoPyRef tmp = PyObject_CallFunctionObjArgs(unlinkOnDestructor,
nullptr);
363 if( PyBool_Check(tmp.get()) )
365 return tmp.get() == Py_True;
371 if( PyList_Check( ob ) )
373 auto sz = PyList_Size( ob );
374 for(
auto i = 0 ;
i < sz ; ++
i )
376 PyObject *elt = PyList_GetItem( ob,
i );
391 AutoPyRef unlinkOnDestructor = PyObject_GetAttrString(ob,meth);
392 AutoPyRef tmp = PyObject_CallFunctionObjArgs(unlinkOnDestructor,
nullptr);
396 if( PyList_Check( ob ) )
398 auto sz = PyList_Size( ob );
399 for(
auto i = 0 ;
i < sz ; ++
i )
401 PyObject *elt = PyList_GetItem( ob,
i );
419 InlineNode(other,father),_autoSqueeze(other._autoSqueeze),_nonSqueezableOutputNodes(other._nonSqueezableOutputNodes)
421 _pynode = Engines::PyScriptNode::_nil();
429 msg <<
"Impossible to set builtins" << __FILE__ <<
":" << __LINE__;
438 _pynode = Engines::PyScriptNode::_nil();
446 msg <<
"Impossible to set builtins" << __FILE__ <<
":" << __LINE__;
465 res=Py_CompileString(
_script.c_str(),
getName().c_str(),Py_file_input);
468 std::string error=
"";
470 PySys_SetObject((
char*)
"stderr", new_stderr);
472 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
473 Py_DECREF(new_stderr);
483 DEBTRACE(
"---------------PyNode::load function---------------" );
492 DEBTRACE(
"---------------PyNode::loadLocal function---------------" );
511 DEBTRACE(
"++++++++++++++ PyNode::executeRemote: " <<
getName() <<
" ++++++++++++++++++++" );
513 throw Exception(
"PythonNode badly loaded");
522 SenderByteImpl *serializationInputCorba =
nullptr;
523 AutoPyRef serializationInput;
525 #if PY_VERSION_HEX < 0x03070000
526 std::unique_lock<std::mutex> lock(
data_mutex);
529 PyObject *
args(0),*ob(0);
534 std::list<InputPort *>::iterator iter2;
544 PyObject_Print(
args,stderr,Py_PRINT_RAW);
547 serializationInput.set(PyObject_CallFunctionObjArgs(
_pyfuncSer,
args,
nullptr));
550 char *serializationInputC(
nullptr);
552 if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
553 throw Exception(
"DistributedPythonNode problem in python pickle");
555 serializationInputCorba =
new SenderByteImpl(serializationInputC,len);
559 std::list<OutputPort *>::iterator iter;
560 Engines::listofstring myseq;
568 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
575 DEBTRACE(
"-----------------starting remote python invocation-----------------" );
576 std::unique_ptr<SALOME::SenderByteSeq> resultCorba;
580 SALOME::SenderByte_var serializationInputRef = serializationInputCorba->_this();
582 _pynode->executeFirst(serializationInputRef);
584 serializationInput.set(
nullptr);
585 resultCorba.reset(
_pynode->executeSecond(myseq) );
588 catch(
const SALOME::SALOME_Exception&
ex )
590 std::ostringstream msg; msg <<
"Exception on remote python invocation" << std::endl <<
ex.details.text.in() << std::endl;
591 msg <<
"PyScriptNode CORBA ref : ";
594 if(!CORBA::is_nil(
orb))
596 CORBA::String_var IOR(
orb->object_to_string(
_pynode));
604 catch(CORBA::COMM_FAILURE&
ex)
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;
613 catch(CORBA::SystemException&
ex)
615 std::ostringstream msg;
616 msg <<
"Exception on remote python invocation." << std::endl ;
617 msg <<
"Caught a CORBA::SystemException." ;
620 CORBA::TypeCode_var tc = tmp.type();
621 const char *
p = tc->name();
630 catch(CORBA::Exception&
ex)
632 std::ostringstream msg;
633 msg <<
"Exception on remote python invocation." << std::endl ;
634 msg <<
"Caught CORBA::Exception. " ;
637 CORBA::TypeCode_var tc = tmp.type();
638 const char *
p = tc->name();
647 catch(omniORB::fatalException& fe)
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;
658 DEBTRACE(
"-----------------end of remote python invocation-----------------" );
663 #if PY_VERSION_HEX < 0x03070000
664 std::unique_lock<std::mutex> lock(
data_mutex);
667 DEBTRACE(
"-----------------PythonNode::outputs-----------------" );
668 int nres( resultCorba->length() );
672 std::string msg=
"Number of output arguments : Mismatch between definition and execution";
684 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
686 SALOME::SenderByte_var elt = (*resultCorba)[pos];
687 SeqByteReceiver recv(elt);
688 unsigned long length = 0;
689 char *resultCorbaC = recv.data(length);
691 AutoPyRef resultPython=PyMemoryView_FromMemory(resultCorbaC,length,PyBUF_READ);
692 AutoPyRef
args = PyTuple_New(1);
693 PyTuple_SetItem(
args,0,resultPython.retn());
697 std::stringstream msg;
698 msg <<
"Conversion with pickle of output ports failed !";
699 msg <<
" : " << __FILE__ <<
":" << __LINE__;
725 cont->removePyScriptNode(
getId().c_str());
727 DEBTRACE(
"++++++++++++++ ENDOF PyNode::executeRemote: " <<
getName() <<
" ++++++++++++++++++++" );
733 DEBTRACE(
"context refcnt: " << context->ob_refcnt );
734 std::ostringstream stream;
735 stream <<
"/tmp/PythonNode_";
737 AutoPyRef code=Py_CompileString(codeStr.c_str(), stream.str().c_str(), Py_file_input);
742 PySys_SetObject((
char*)
"stderr", new_stderr);
744 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
748 AutoPyRef res = PyEval_EvalCode( code, context, context);
750 DEBTRACE(
"context refcnt: " << context->ob_refcnt );
753 if(PyErr_Occurred ())
757 PySys_SetObject((
char*)
"stderr", new_stderr);
758 ofstream errorfile(stream.str().c_str());
759 if (errorfile.is_open())
761 errorfile << codeStr;
765 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
777 DEBTRACE(
"++++++++++++++ PyNode::executeLocal: " <<
getName() <<
" ++++++++++++++++++++" );
780 std::ostringstream unpxy; unpxy <<
"from SALOME_PyNode import UnProxyObjectSimpleLocal" << std::endl;
781 DEBTRACE(
"---------------PyNode::inputs---------------" );
782 list<InputPort *>::iterator iter2;
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;
792 PyObject_Print(ob,stderr,Py_PRINT_RAW);
796 DEBTRACE(
"after PyDict_SetItemString:ob refcnt: " << ob->ob_refcnt );
799 DEBTRACE(
"---------------End PyNode::inputs---------------" );
802 DEBTRACE(
"----------------PyNode::calculation---------------" );
809 DEBTRACE(
"-----------------PyNode::outputs-----------------" );
810 list<OutputPort *>::iterator iter;
817 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
821 std::string msg=
"Error during execution: there is no variable ";
822 msg=msg+
p->
getName()+
" in node context";
826 DEBTRACE(
"PyNode::outputs::ob refcnt: " << ob->ob_refcnt );
828 PyObject_Print(ob,stderr,Py_PRINT_RAW);
843 DEBTRACE(
"-----------------End PyNode::outputs-----------------" );
848 AutoPyRef pStr = PyUnicode_FromString( (*iter2)->getName().c_str() );
849 if( PyDict_Contains(
_context,pStr) == 1 )
854 DEBTRACE(
"++++++++++++++ End PyNode::execute: " <<
getName() <<
" ++++++++++++++++++++" );
919 DEBTRACE(
"PythonNode::shutdown " << level);
920 if(
_mode==
"local")
return;
929 const std::string& container_name)
931 if(!resource_name.empty() && !container_name.empty())
951 return "DEFAULT_NAME_FOR_UNIQUE_PYTHON_NODE_ENTRY";
974 DEBTRACE(
"Trouble when pynode->UnRegister!")
976 _pynode = Engines::PyScriptNode::_nil();
994 Engines::PyScriptNode_var ret(objContainer->getDefaultPyScriptNode(
pythonEntryName().c_str()));
995 if(!CORBA::is_nil(ret))
999 return Engines::PyNodeBase::_narrow(ret);
1005 _pynode=Engines::PyScriptNode::_narrow(remoteInterp);
1008 Engines::PyScriptNode_var tmpp(Engines::PyScriptNode::_narrow(remoteInterp));
1009 if(!
_pynode->_is_equivalent(tmpp))
1012 _pynode=Engines::PyScriptNode::_narrow(remoteInterp);
1020 return Engines::PyNodeBase::_narrow(
_pynode);
1028 list<InputPort *>::iterator iter;
1033 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1034 n->edAddInputPort(
p->
getName(),
p->edGetType());
1036 list<OutputPort *>::iterator iter2;
1041 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1042 n->edAddOutputPort(
p->
getName(),
p->edGetType());
1056 std::size_t sz(ret.size());
1058 for(std::size_t
i=0;
i<sz;
i++)
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);
1069 Engines::pickledArgs_var serializationInputCorba(
new Engines::pickledArgs);
1072 PyObject *serializationInput(PyObject_CallFunctionObjArgs(
_pyfuncSimpleSer,ob,NULL));
1074 char *serializationInputC(0);
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);
1103 msg <<
"Not possible to set builtins" << __FILE__ <<
":" << __LINE__;
1114 DEBTRACE(
"PyFuncNode::PyFuncNode " << name );
1122 msg <<
"Not possible to set builtins" << __FILE__ <<
":" << __LINE__;
1158 res=Py_CompileString(
_script.c_str(),
getName().c_str(),Py_file_input);
1161 std::string error=
"";
1163 PySys_SetObject((
char*)
"stderr", new_stderr);
1165 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1166 Py_DECREF(new_stderr);
1176 DEBTRACE(
"---------------PyfuncNode::load function---------------" );
1190 DEBTRACE(
"---------------PyFuncNode::load function " <<
getName() <<
" ---------------" );
1194 list<OutputPort *>::iterator iter;
1199 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1207 std::ostringstream stream;
1208 stream <<
"/tmp/PythonNode_";
1211 PyObject* code=Py_CompileString(
_script.c_str(), stream.str().c_str(), Py_file_input);
1216 PySys_SetObject((
char*)
"stderr", new_stderr);
1218 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1219 Py_DECREF(new_stderr);
1220 throw Exception(
"Error during execution");
1227 if(PyErr_Occurred ())
1231 PySys_SetObject((
char*)
"stderr", new_stderr);
1232 ofstream errorfile(stream.str().c_str());
1233 if (errorfile.is_open())
1239 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1240 Py_DECREF(new_stderr);
1241 throw Exception(
"Error during execution");
1250 PySys_SetObject((
char*)
"stderr", new_stderr);
1252 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1253 Py_DECREF(new_stderr);
1254 throw Exception(
"Error during execution");
1256 DEBTRACE(
"---------------End PyFuncNode::load function---------------" );
1270 DEBTRACE(
"++++++++++++++ PyFuncNode::executeRemote: " <<
getName() <<
" ++++++++++++++++++++" );
1272 throw Exception(
"DistributedPythonNode badly loaded");
1281 Engines::pickledArgs_var serializationInputCorba(
new Engines::pickledArgs);;
1283 #if PY_VERSION_HEX < 0x03070000
1284 std::unique_lock<std::mutex> lock(
data_mutex);
1298 PyTuple_SetItem(
args,pos,ob);
1301 PyObject_Print(
args,stderr,Py_PRINT_RAW);
1304 PyObject *serializationInput=PyObject_CallObject(
_pyfuncSer,
args);
1307 char *serializationInputC(0);
1309 if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
1310 throw Exception(
"DistributedPythonNode problem in python pickle");
1312 serializationInputCorba->length(len);
1313 for(
int i=0;
i < len ;
i++)
1314 serializationInputCorba[
i]=serializationInputC[
i];
1315 Py_DECREF(serializationInput);
1321 DEBTRACE(
"-----------------starting remote python invocation-----------------" );
1322 Engines::pickledArgs_var resultCorba;
1325 resultCorba=
_pynode->execute(
getFname().c_str(),serializationInputCorba);
1327 catch(
const SALOME::SALOME_Exception&
ex )
1329 std::string msg=
"Exception on remote python invocation";
1331 msg +=
ex.details.text.in();
1335 catch(CORBA::COMM_FAILURE&
ex)
1337 std::ostringstream msg;
1338 msg <<
"Exception on remote python invocation." << std::endl ;
1339 msg <<
"Caught system exception COMM_FAILURE -- unable to contact the "
1340 <<
"object." << std::endl;
1344 catch(CORBA::SystemException&
ex)
1346 std::ostringstream msg;
1347 msg <<
"Exception on remote python invocation." << std::endl ;
1348 msg <<
"Caught a CORBA::SystemException." ;
1351 CORBA::TypeCode_var tc = tmp.type();
1352 const char *
p = tc->name();
1361 catch(CORBA::Exception&
ex)
1363 std::ostringstream msg;
1364 msg <<
"Exception on remote python invocation." << std::endl ;
1365 msg <<
"Caught CORBA::Exception. " ;
1368 CORBA::TypeCode_var tc = tmp.type();
1369 const char *
p = tc->name();
1378 catch(omniORB::fatalException& fe)
1380 std::ostringstream msg;
1381 msg <<
"Exception on remote python invocation." << std::endl ;
1382 msg <<
"Caught omniORB::fatalException:" << std::endl;
1383 msg <<
" file: " << fe.file() << std::endl;
1384 msg <<
" line: " << fe.line() << std::endl;
1385 msg <<
" mesg: " << fe.errmsg() << std::endl;
1389 DEBTRACE(
"-----------------end of remote python invocation-----------------" );
1393 char *resultCorbaC=
new char[resultCorba->length()+1];
1394 resultCorbaC[resultCorba->length()]=
'\0';
1395 for(
int i=0;
i<resultCorba->length();
i++)
1396 resultCorbaC[
i]=resultCorba[
i];
1399 #if PY_VERSION_HEX < 0x03070000
1400 std::unique_lock<std::mutex> lock(
data_mutex);
1404 PyObject *resultPython(PyBytes_FromStringAndSize(resultCorbaC,resultCorba->length()));
1405 delete [] resultCorbaC;
1406 PyObject *
args(PyTuple_New(1)),*ob(0);
1407 PyTuple_SetItem(
args,0,resultPython);
1411 DEBTRACE(
"-----------------PythonNode::outputs-----------------" );
1413 if(finalResult == Py_None)
1415 else if(PyTuple_Check(finalResult))
1416 nres=PyTuple_Size(finalResult);
1420 std::string msg=
"Number of output arguments : Mismatch between definition and execution";
1421 Py_DECREF(finalResult);
1433 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1435 if(PyTuple_Check(finalResult))
1436 ob=PyTuple_GetItem(finalResult,pos) ;
1439 DEBTRACE(
"ob refcnt: " << ob->ob_refcnt );
1442 Py_DECREF(finalResult);
1446 Py_DECREF(finalResult);
1452 DEBTRACE(
"++++++++++++++ ENDOF PyFuncNode::executeRemote: " <<
getName() <<
" ++++++++++++++++++++" );
1457 DEBTRACE(
"++++++++++++++ PyFuncNode::execute: " <<
getName() <<
" ++++++++++++++++++++" );
1464 DEBTRACE(
"---------------PyFuncNode::inputs---------------" );
1466 list<InputPort *>::iterator iter2;
1471 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1474 PyObject_Print(ob,stderr,Py_PRINT_RAW);
1477 DEBTRACE(
"ob refcnt: " << ob->ob_refcnt );
1479 PyTuple_SetItem(
args,pos,ob);
1480 DEBTRACE(
"ob refcnt: " << ob->ob_refcnt );
1483 DEBTRACE(
"---------------End PyFuncNode::inputs---------------" );
1485 DEBTRACE(
"----------------PyFuncNode::calculation---------------" );
1487 PyObject_Print(
_pyfunc,stderr,Py_PRINT_RAW);
1489 PyObject_Print(
args,stderr,Py_PRINT_RAW);
1493 PyObject* result = PyObject_CallObject(
_pyfunc ,
args ) ;
1502 PySys_SetObject((
char*)
"stderr", new_stderr);
1503 std::ostringstream stream;
1504 stream <<
"/tmp/PythonNode_";
1506 ofstream errorfile(stream.str().c_str());
1507 if (errorfile.is_open())
1513 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1514 Py_DECREF(new_stderr);
1515 throw Exception(
"Error during execution");
1517 DEBTRACE(
"----------------End PyFuncNode::calculation---------------" );
1519 DEBTRACE(
"-----------------PyFuncNode::outputs-----------------" );
1521 if(result == Py_None)
1523 else if(PyTuple_Check(result))
1524 nres=PyTuple_Size(result);
1528 std::string msg=
"Number of output arguments : Mismatch between definition and execution";
1536 PyObject_Print(result,stderr,Py_PRINT_RAW);
1539 list<OutputPort *>::iterator iter;
1546 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1548 if(PyTuple_Check(result))ob=PyTuple_GetItem(result,pos) ;
1550 DEBTRACE(
"ob refcnt: " << ob->ob_refcnt );
1552 PyObject_Print(ob,stderr,Py_PRINT_RAW);
1565 DEBTRACE(
"-----------------End PyFuncNode::outputs-----------------" );
1568 DEBTRACE(
"++++++++++++++ End PyFuncNode::execute: " <<
getName() <<
" ++++++++++++++++++++" );
1585 Engines::PyNode_var ret(objContainer->getDefaultPyNode(
getName().c_str()));
1586 if(!CORBA::is_nil(ret))
1590 return Engines::PyNodeBase::_narrow(ret);
1597 Engines::PyNode_var tmpp(Engines::PyNode::_narrow(remoteInterp));
1598 if(
_pynode->_is_equivalent(tmpp))
1603 _pynode=Engines::PyNode::_narrow(remoteInterp);
1608 return Engines::PyNodeBase::_narrow(
_pynode);
1617 list<InputPort *>::iterator iter;
1621 n->edAddInputPort(
p->
getName(),
p->edGetType());
1623 list<OutputPort *>::iterator iter2;
1627 n->edAddOutputPort(
p->
getName(),
p->edGetType());
1639 DEBTRACE(
"PyFuncNode::shutdown " << level);
1640 if(
_mode==
"local")
return;
1644 _pynode=Engines::PyNode::_nil();
1650 const std::string& container_name)
1652 if(!resource_name.empty() && !container_name.empty())
static char SCRIPT_FOR_BIGOBJECT[]
static std::mutex data_mutex
Engines::Container_var GetContainerObj(InlineNode *reqNode, bool &isStandardCont)
#define DEBUG_YACSTRACE(msg)
Base class for all composed nodes.
std::string getName() const
virtual void start(const Task *askingNode)=0
virtual void shutdown(int level)=0
virtual bool isAlreadyStarted(const Task *askingNode) const =0
virtual std::string getProperty(const std::string &name) const =0
virtual bool isUsingPythonCache()
virtual bool canAcceptImposedResource()
int getNumberOfOutputPorts() const
int getNumberOfInputPorts() const
std::list< InputPort * > _setOfInputPort
void initCommonPartWithoutStateManagement(bool start)
std::list< OutputPort * > _setOfOutputPort
virtual void checkBasicConsistency() const
static const char INITIALIZE_SCRIPT_KEY[]
bool canSafelySqueezeMemory() const
Class for calculation node (function) inlined (and executed) in the schema.
virtual void checkBasicConsistency() const
virtual std::string getFname()
Class for calculation node (script) inlined (and executed) in the schema.
virtual Container * getContainer()
virtual std::string getScript()
Base class for all nodes.
virtual void setErrorDetails(const std::string &error)
std::vector< std::pair< std::string, int > > getDPLScopeInfo(ComposedNode *gfn)
const std::string getId() const
void setState(YACS::StatesForNode theState)
Sets the given state for node.
std::string _implementation
virtual void exDisabledState()
Notify this node that it has been disabled.
const std::string & getName() const
std::string _errorDetails
YACS::StatesForNode _state
void putWithoutForward(PyObject *data)
Engines::PyNodeBase_var getRemoteInterpreterHandle()
bool hasImposedResource() const override
virtual void shutdown(int level)
Stop all pending activities of the node.
virtual void executeRemote()
virtual void loadRemote()
virtual void executeLocal()
virtual void checkBasicConsistency() const
static const char SCRIPT_FOR_SERIALIZATION[]
std::string getContainerLog()
returns a string that contains the name of the container log file if it exists
void imposeResource(const std::string &resource_name, const std::string &container_name) override
Node * simpleClone(ComposedNode *father, bool editionOnly) const
Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const
returns (if any) an object, you have to deal with (UnRegister)
void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp)
PyFuncNode * cloneNode(const std::string &name)
Create a new node of same type with a given name.
virtual void init(bool start=true)
void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer)
returns an object, you have to deal with (UnRegister)
bool canAcceptImposedResource() override
Engines::PyNode_var _pynode
PyFuncNode(const PyFuncNode &other, ComposedNode *father)
void loadRemoteContext(InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested)
static void UnlinkOnDestructorIfProxy(PyObject *ob)
virtual const char * getSerializationScript() const =0
std::string _imposedResource
virtual bool hasImposedResource() const
static bool GetDestroyStatus(PyObject *ob)
void commonRemoteLoad(InlineNode *reqNode)
virtual Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const =0
returns (if any) an object, you have to deal with (UnRegister)
static PyObject * _pyClsBigObject
static void IfProxyDoSomething(PyObject *ob, const char *meth)
Engines::Container_var loadPythonAdapter(InlineNode *reqNode, bool &isInitializeRequested)
static void DoNotTouchFileIfProxy(PyObject *ob)
PyObject * _pyfuncSimpleSer
static const char SCRIPT_FOR_SIMPLE_SERIALIZATION[]
void loadRemoteContainer(InlineNode *reqNode)
static std::string GetContainerLog(const std::string &mode, Container *container, const Task *askingTask)
static bool IsProxy(PyObject *ob)
virtual void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer)=0
returns an object, you have to deal with (UnRegister)
virtual Engines::PyNodeBase_var getRemoteInterpreterHandle()=0
std::string _imposedContainer
virtual void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp)=0
virtual void checkBasicConsistency() const
std::string pythonEntryName() const
void setSqueezeStatus(bool sqStatus)
bool hasImposedResource() const override
Engines::PyScriptNode_var _pynode
virtual void executeRemote()
static const char REMOTE_NAME[]
bool isUsingPythonCache() const
virtual void shutdown(int level)
Stop all pending activities of the node.
static const char SCRIPT_FOR_SERIALIZATION[]
void squeezeMemoryRemote()
static void ExecuteLocalInternal(const std::string &codeStr, PyObject *context, std::string &errorDetails)
PythonNode(const PythonNode &other, ComposedNode *father)
void executeLocalInternal(const std::string &codeStr)
Node * simpleClone(ComposedNode *father, bool editionOnly) const
bool canAcceptImposedResource() override
static const char IMPL_NAME[]
void createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer)
returns an object, you have to deal with (UnRegister)
virtual void loadRemote()
void imposeResource(const std::string &resource_name, const std::string &container_name) override
std::set< std::string > _nonSqueezableOutputNodes
list on output port name excluded from the squeeze mecanism
Engines::PyNodeBase_var getRemoteInterpreterHandle()
static const char DPL_INFO_NAME[]
void assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp)
virtual void executeLocal()
std::string getContainerLog()
returns a string that contains the name of the container log file if it exists
void applyDPLScope(ComposedNode *gfn)
void setSqueezeStatusWithExceptions(bool sqStatus, const std::vector< std::string > &squeezeExceptions)
Engines::PyNodeBase_var retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const
returns (if any) an object, you have to deal with (UnRegister)
bool getSqueezeStatus() const
PythonNode * cloneNode(const std::string &name)
Create a new node of same type with a given name.
static SalomeContainerTmpForHP * BuildFrom(const SalomeHPContainer *cont, const Task *askingNode)
Engines::Container_ptr getContainerPtr(const Task *askingNode) const
const char * what(void) const noexcept
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()
PyObject * newPyStdOut(std::string &out)