24#include "PythonCppUtils.hxx"
30#include "ReceiverFactory.hxx"
31#include "SenderByteImpl.hxx"
44#if PY_VERSION_HEX < 0x02050000
54const char PythonEntry::SCRIPT_FOR_SIMPLE_SERIALIZATION[]=
"import pickle\n"
55 "def pickleForVarSimplePyth2009(val):\n"
56 " return pickle.dumps(val,-1)\n"
59PyObject *PythonEntry::_pyClsBigObject =
nullptr;
61const char PythonNode::IMPL_NAME[]=
"Python";
62const char PythonNode::KIND[]=
"Python";
64const char PythonNode::SCRIPT_FOR_SERIALIZATION[]=
"import pickle\n"
65 "def pickleForDistPyth2009(kws):\n"
66 " return pickle.dumps(((),kws),-1)\n"
68 "def unPickleForDistPyth2009(st):\n"
69 " args=pickle.loads(st)\n"
72const char PythonNode::REMOTE_NAME[]=
"remote";
74const char PythonNode::DPL_INFO_NAME[]=
"my_dpl_localization";
76const char PyFuncNode::SCRIPT_FOR_SERIALIZATION[]=
"import pickle\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
93PythonEntry::PythonEntry():_context(0),_pyfuncSer(0),_pyfuncUnser(0),_pyfuncSimpleSer(0)
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 );
419InlineNode(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);
586 serializationInput.set(
nullptr);
588 resultCorba.reset(
_pynode->executeSecond(myseq) );
591 catch(
const SALOME::SALOME_Exception&
ex )
593 std::ostringstream msg; msg <<
"Exception on remote python invocation" << std::endl <<
ex.details.text.in() << std::endl;
594 msg <<
"PyScriptNode CORBA ref : ";
597 if(!CORBA::is_nil(
orb))
599 CORBA::String_var IOR(
orb->object_to_string(
_pynode));
607 catch(CORBA::COMM_FAILURE&
ex)
609 std::ostringstream msg;
610 msg <<
"Exception on remote python invocation." << std::endl ;
611 msg <<
"Caught system exception COMM_FAILURE -- unable to contact the "
612 <<
"object." << std::endl;
616 catch(CORBA::SystemException&
ex)
618 std::ostringstream msg;
619 msg <<
"Exception on remote python invocation." << std::endl ;
620 msg <<
"Caught a CORBA::SystemException." ;
623 CORBA::TypeCode_var tc = tmp.type();
624 const char *
p = tc->name();
633 catch(CORBA::Exception&
ex)
635 std::ostringstream msg;
636 msg <<
"Exception on remote python invocation." << std::endl ;
637 msg <<
"Caught CORBA::Exception. " ;
640 CORBA::TypeCode_var tc = tmp.type();
641 const char *
p = tc->name();
650 catch(omniORB::fatalException& fe)
652 std::ostringstream msg;
653 msg <<
"Exception on remote python invocation." << std::endl ;
654 msg <<
"Caught omniORB::fatalException:" << std::endl;
655 msg <<
" file: " << fe.file() << std::endl;
656 msg <<
" line: " << fe.line() << std::endl;
657 msg <<
" mesg: " << fe.errmsg() << std::endl;
661 DEBTRACE(
"-----------------end of remote python invocation-----------------" );
666#if PY_VERSION_HEX < 0x03070000
667 std::unique_lock<std::mutex> lock(
data_mutex);
670 DEBTRACE(
"-----------------PythonNode::outputs-----------------" );
671 int nres( resultCorba->length() );
675 std::string msg=
"Number of output arguments : Mismatch between definition and execution";
687 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
689 SALOME::SenderByte_var elt = (*resultCorba)[pos];
690 SeqByteReceiver recv(elt);
691 unsigned long length = 0;
692 char *resultCorbaC = recv.data(length);
694 AutoPyRef resultPython=PyMemoryView_FromMemory(resultCorbaC,length,PyBUF_READ);
695 AutoPyRef
args = PyTuple_New(1);
696 PyTuple_SetItem(
args,0,resultPython.retn());
700 std::stringstream msg;
701 msg <<
"Conversion with pickle of output ports failed !";
702 msg <<
" : " << __FILE__ <<
":" << __LINE__;
728 cont->removePyScriptNode(
getId().c_str());
730 DEBTRACE(
"++++++++++++++ ENDOF PyNode::executeRemote: " <<
getName() <<
" ++++++++++++++++++++" );
736 DEBTRACE(
"context refcnt: " << context->ob_refcnt );
737 std::ostringstream stream;
738 stream <<
"/tmp/PythonNode_";
740 AutoPyRef code=Py_CompileString(codeStr.c_str(), stream.str().c_str(), Py_file_input);
745 PySys_SetObject((
char*)
"stderr", new_stderr);
747 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
751 AutoPyRef res = PyEval_EvalCode( code, context, context);
753 DEBTRACE(
"context refcnt: " << context->ob_refcnt );
756 if(PyErr_Occurred ())
760 PySys_SetObject((
char*)
"stderr", new_stderr);
761 ofstream errorfile(stream.str().c_str());
762 if (errorfile.is_open())
764 errorfile << codeStr;
768 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
780 DEBTRACE(
"++++++++++++++ PyNode::executeLocal: " <<
getName() <<
" ++++++++++++++++++++" );
783 std::ostringstream unpxy; unpxy <<
"from SALOME_PyNode import UnProxyObjectSimpleLocal" << std::endl;
784 DEBTRACE(
"---------------PyNode::inputs---------------" );
785 list<InputPort *>::iterator iter2;
790 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
791 PyObject* ob=
p->getPyObj();
792 DEBTRACE(
"ob refcnt: " << ob->ob_refcnt );
793 unpxy <<
p->
getName() <<
" = UnProxyObjectSimpleLocal( " <<
p->
getName() <<
" )" << std::endl;
795 PyObject_Print(ob,stderr,Py_PRINT_RAW);
799 DEBTRACE(
"after PyDict_SetItemString:ob refcnt: " << ob->ob_refcnt );
802 DEBTRACE(
"---------------End PyNode::inputs---------------" );
805 DEBTRACE(
"----------------PyNode::calculation---------------" );
812 DEBTRACE(
"-----------------PyNode::outputs-----------------" );
813 list<OutputPort *>::iterator iter;
820 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
824 std::string msg=
"Error during execution: there is no variable ";
825 msg=msg+
p->
getName()+
" in node context";
829 DEBTRACE(
"PyNode::outputs::ob refcnt: " << ob->ob_refcnt );
831 PyObject_Print(ob,stderr,Py_PRINT_RAW);
846 DEBTRACE(
"-----------------End PyNode::outputs-----------------" );
851 AutoPyRef pStr = PyUnicode_FromString( (*iter2)->getName().c_str() );
852 if( PyDict_Contains(
_context,pStr) == 1 )
857 DEBTRACE(
"++++++++++++++ End PyNode::execute: " <<
getName() <<
" ++++++++++++++++++++" );
922 DEBTRACE(
"PythonNode::shutdown " << level);
923 if(
_mode==
"local")
return;
932 const std::string& container_name)
934 if(!resource_name.empty() && !container_name.empty())
954 return "DEFAULT_NAME_FOR_UNIQUE_PYTHON_NODE_ENTRY";
977 DEBTRACE(
"Trouble when pynode->UnRegister!")
979 _pynode = Engines::PyScriptNode::_nil();
997 Engines::PyScriptNode_var ret(objContainer->getDefaultPyScriptNode(
pythonEntryName().c_str()));
998 if(!CORBA::is_nil(ret))
1002 return Engines::PyNodeBase::_narrow(ret);
1008 _pynode=Engines::PyScriptNode::_narrow(remoteInterp);
1011 Engines::PyScriptNode_var tmpp(Engines::PyScriptNode::_narrow(remoteInterp));
1012 if(!
_pynode->_is_equivalent(tmpp))
1015 _pynode=Engines::PyScriptNode::_narrow(remoteInterp);
1023 return Engines::PyNodeBase::_narrow(
_pynode);
1031 list<InputPort *>::iterator iter;
1036 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1037 n->edAddInputPort(
p->
getName(),
p->edGetType());
1039 list<OutputPort *>::iterator iter2;
1044 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1045 n->edAddOutputPort(
p->
getName(),
p->edGetType());
1059 std::size_t sz(ret.size());
1061 for(std::size_t
i=0;
i<sz;
i++)
1063 const std::pair<std::string,int>&
p(ret[
i]);
1064 PyObject *elt(PyTuple_New(2));
1065 PyTuple_SetItem(elt,0,PyUnicode_FromString(
p.first.c_str()));
1066 PyTuple_SetItem(elt,1,PyLong_FromLong(
p.second));
1067 PyList_SetItem(ob,
i,elt);
1072 Engines::pickledArgs_var serializationInputCorba(
new Engines::pickledArgs);
1075 PyObject *serializationInput(PyObject_CallFunctionObjArgs(
_pyfuncSimpleSer,ob,NULL));
1077 char *serializationInputC(0);
1079 if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
1080 throw Exception(
"DistributedPythonNode problem in python pickle");
1081 serializationInputCorba->length(len);
1082 for(
int i=0;
i < len ;
i++)
1083 serializationInputCorba[
i]=serializationInputC[
i];
1084 Py_XDECREF(serializationInput);
1106 msg <<
"Not possible to set builtins" << __FILE__ <<
":" << __LINE__;
1117 DEBTRACE(
"PyFuncNode::PyFuncNode " << name );
1125 msg <<
"Not possible to set builtins" << __FILE__ <<
":" << __LINE__;
1161 res=Py_CompileString(
_script.c_str(),
getName().c_str(),Py_file_input);
1164 std::string error=
"";
1166 PySys_SetObject((
char*)
"stderr", new_stderr);
1168 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1169 Py_DECREF(new_stderr);
1179 DEBTRACE(
"---------------PyfuncNode::load function---------------" );
1193 DEBTRACE(
"---------------PyFuncNode::load function " <<
getName() <<
" ---------------" );
1197 list<OutputPort *>::iterator iter;
1202 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1210 std::ostringstream stream;
1211 stream <<
"/tmp/PythonNode_";
1214 PyObject* code=Py_CompileString(
_script.c_str(), stream.str().c_str(), Py_file_input);
1219 PySys_SetObject((
char*)
"stderr", new_stderr);
1221 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1222 Py_DECREF(new_stderr);
1223 throw Exception(
"Error during execution");
1230 if(PyErr_Occurred ())
1234 PySys_SetObject((
char*)
"stderr", new_stderr);
1235 ofstream errorfile(stream.str().c_str());
1236 if (errorfile.is_open())
1242 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1243 Py_DECREF(new_stderr);
1244 throw Exception(
"Error during execution");
1253 PySys_SetObject((
char*)
"stderr", new_stderr);
1255 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1256 Py_DECREF(new_stderr);
1257 throw Exception(
"Error during execution");
1259 DEBTRACE(
"---------------End PyFuncNode::load function---------------" );
1273 DEBTRACE(
"++++++++++++++ PyFuncNode::executeRemote: " <<
getName() <<
" ++++++++++++++++++++" );
1275 throw Exception(
"DistributedPythonNode badly loaded");
1284 Engines::pickledArgs_var serializationInputCorba(
new Engines::pickledArgs);;
1286#if PY_VERSION_HEX < 0x03070000
1287 std::unique_lock<std::mutex> lock(
data_mutex);
1301 PyTuple_SetItem(
args,pos,ob);
1304 PyObject_Print(
args,stderr,Py_PRINT_RAW);
1307 PyObject *serializationInput=PyObject_CallObject(
_pyfuncSer,
args);
1310 char *serializationInputC(0);
1312 if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
1313 throw Exception(
"DistributedPythonNode problem in python pickle");
1315 serializationInputCorba->length(len);
1316 for(
int i=0;
i < len ;
i++)
1317 serializationInputCorba[
i]=serializationInputC[
i];
1318 Py_DECREF(serializationInput);
1324 DEBTRACE(
"-----------------starting remote python invocation-----------------" );
1325 Engines::pickledArgs_var resultCorba;
1328 resultCorba=
_pynode->execute(
getFname().c_str(),serializationInputCorba);
1330 catch(
const SALOME::SALOME_Exception&
ex )
1332 std::string msg=
"Exception on remote python invocation";
1334 msg +=
ex.details.text.in();
1338 catch(CORBA::COMM_FAILURE&
ex)
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;
1347 catch(CORBA::SystemException&
ex)
1349 std::ostringstream msg;
1350 msg <<
"Exception on remote python invocation." << std::endl ;
1351 msg <<
"Caught a CORBA::SystemException." ;
1354 CORBA::TypeCode_var tc = tmp.type();
1355 const char *
p = tc->name();
1364 catch(CORBA::Exception&
ex)
1366 std::ostringstream msg;
1367 msg <<
"Exception on remote python invocation." << std::endl ;
1368 msg <<
"Caught CORBA::Exception. " ;
1371 CORBA::TypeCode_var tc = tmp.type();
1372 const char *
p = tc->name();
1381 catch(omniORB::fatalException& fe)
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;
1392 DEBTRACE(
"-----------------end of remote python invocation-----------------" );
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];
1402#if PY_VERSION_HEX < 0x03070000
1403 std::unique_lock<std::mutex> lock(
data_mutex);
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);
1414 DEBTRACE(
"-----------------PythonNode::outputs-----------------" );
1416 if(finalResult == Py_None)
1418 else if(PyTuple_Check(finalResult))
1419 nres=PyTuple_Size(finalResult);
1423 std::string msg=
"Number of output arguments : Mismatch between definition and execution";
1424 Py_DECREF(finalResult);
1436 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1438 if(PyTuple_Check(finalResult))
1439 ob=PyTuple_GetItem(finalResult,pos) ;
1442 DEBTRACE(
"ob refcnt: " << ob->ob_refcnt );
1445 Py_DECREF(finalResult);
1449 Py_DECREF(finalResult);
1455 DEBTRACE(
"++++++++++++++ ENDOF PyFuncNode::executeRemote: " <<
getName() <<
" ++++++++++++++++++++" );
1460 DEBTRACE(
"++++++++++++++ PyFuncNode::execute: " <<
getName() <<
" ++++++++++++++++++++" );
1467 DEBTRACE(
"---------------PyFuncNode::inputs---------------" );
1469 list<InputPort *>::iterator iter2;
1474 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1477 PyObject_Print(ob,stderr,Py_PRINT_RAW);
1480 DEBTRACE(
"ob refcnt: " << ob->ob_refcnt );
1482 PyTuple_SetItem(
args,pos,ob);
1483 DEBTRACE(
"ob refcnt: " << ob->ob_refcnt );
1486 DEBTRACE(
"---------------End PyFuncNode::inputs---------------" );
1488 DEBTRACE(
"----------------PyFuncNode::calculation---------------" );
1490 PyObject_Print(
_pyfunc,stderr,Py_PRINT_RAW);
1492 PyObject_Print(
args,stderr,Py_PRINT_RAW);
1496 PyObject* result = PyObject_CallObject(
_pyfunc ,
args ) ;
1505 PySys_SetObject((
char*)
"stderr", new_stderr);
1506 std::ostringstream stream;
1507 stream <<
"/tmp/PythonNode_";
1509 ofstream errorfile(stream.str().c_str());
1510 if (errorfile.is_open())
1516 PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
1517 Py_DECREF(new_stderr);
1518 throw Exception(
"Error during execution");
1520 DEBTRACE(
"----------------End PyFuncNode::calculation---------------" );
1522 DEBTRACE(
"-----------------PyFuncNode::outputs-----------------" );
1524 if(result == Py_None)
1526 else if(PyTuple_Check(result))
1527 nres=PyTuple_Size(result);
1531 std::string msg=
"Number of output arguments : Mismatch between definition and execution";
1539 PyObject_Print(result,stderr,Py_PRINT_RAW);
1542 list<OutputPort *>::iterator iter;
1549 DEBTRACE(
"port kind: " <<
p->edGetType()->kind() );
1551 if(PyTuple_Check(result))ob=PyTuple_GetItem(result,pos) ;
1553 DEBTRACE(
"ob refcnt: " << ob->ob_refcnt );
1555 PyObject_Print(ob,stderr,Py_PRINT_RAW);
1568 DEBTRACE(
"-----------------End PyFuncNode::outputs-----------------" );
1571 DEBTRACE(
"++++++++++++++ End PyFuncNode::execute: " <<
getName() <<
" ++++++++++++++++++++" );
1588 Engines::PyNode_var ret(objContainer->getDefaultPyNode(
getName().c_str()));
1589 if(!CORBA::is_nil(ret))
1593 return Engines::PyNodeBase::_narrow(ret);
1600 Engines::PyNode_var tmpp(Engines::PyNode::_narrow(remoteInterp));
1601 if(
_pynode->_is_equivalent(tmpp))
1606 _pynode=Engines::PyNode::_narrow(remoteInterp);
1611 return Engines::PyNodeBase::_narrow(
_pynode);
1620 list<InputPort *>::iterator iter;
1624 n->edAddInputPort(
p->
getName(),
p->edGetType());
1626 list<OutputPort *>::iterator iter2;
1630 n->edAddOutputPort(
p->
getName(),
p->edGetType());
1642 DEBTRACE(
"PyFuncNode::shutdown " << level);
1643 if(
_mode==
"local")
return;
1647 _pynode=Engines::PyNode::_nil();
1653 const std::string& container_name)
1655 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 & getName() const
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.
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
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)
std::string _imposedResource
virtual bool hasImposedResource() const
static bool GetDestroyStatus(PyObject *ob)
virtual const char * getSerializationScript() const =0
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.
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)