1 // Copyright (C) 2006-2023 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "RuntimeSALOME.hxx"
21 #include "PythonNode.hxx"
22 #include "PythonPorts.hxx"
23 #include "TypeCode.hxx"
24 #include "PythonCppUtils.hxx"
25 #include "Container.hxx"
26 #include "SalomeContainer.hxx"
27 #include "SalomeHPContainer.hxx"
28 #include "SalomeContainerTmpForHP.hxx"
29 #include "ConversionException.hxx"
30 #include "ReceiverFactory.hxx"
31 #include "SenderByteImpl.hxx"
33 #include "PyStdout.hxx"
41 #define getpid _getpid
44 #if PY_VERSION_HEX < 0x02050000
45 typedef int Py_ssize_t;
49 #include "YacsTrace.hxx"
51 using namespace YACS::ENGINE;
54 const char PythonEntry::SCRIPT_FOR_SIMPLE_SERIALIZATION[]="import pickle\n"
55 "def pickleForVarSimplePyth2009(val):\n"
56 " return pickle.dumps(val,-1)\n"
59 PyObject *PythonEntry::_pyClsBigObject = nullptr;
61 const char PythonNode::IMPL_NAME[]="Python";
62 const char PythonNode::KIND[]="Python";
64 const 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"
72 const char PythonNode::REMOTE_NAME[]="remote";
74 const char PythonNode::DPL_INFO_NAME[]="my_dpl_localization";
76 const 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"
84 static char SCRIPT_FOR_BIGOBJECT[]="import SALOME_PyNode\n"
85 "BigObjectOnDiskBase = SALOME_PyNode.BigObjectOnDiskBase\n";
87 // pickle.load concurrency issue : see https://bugs.python.org/issue12680
88 #if PY_VERSION_HEX < 0x03070000
90 static std::mutex data_mutex;
93 PythonEntry::PythonEntry():_context(0),_pyfuncSer(0),_pyfuncUnser(0),_pyfuncSimpleSer(0)
97 PythonEntry::~PythonEntry()
100 DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
101 // not Py_XDECREF of _pyfuncUnser because it is returned by PyDict_GetItem -> borrowed
102 // not Py_XDECREF of _pyfuncSer because it is returned by PyDict_GetItem -> borrowed
103 Py_XDECREF(_context);
106 void PythonEntry::loadRemoteContainer(InlineNode *reqNode)
108 DEBTRACE( "---------------PythonEntry::CommonRemoteLoad function---------------" );
109 Container *container(reqNode->getContainer());
110 bool isContAlreadyStarted(false);
115 if(hasImposedResource())
116 container->start(reqNode, _imposedResource, _imposedContainer);
119 isContAlreadyStarted=container->isAlreadyStarted(reqNode);
120 if(!isContAlreadyStarted)
121 container->start(reqNode);
126 reqNode->setErrorDetails(e.what());
132 std::string what("PythonEntry::CommonRemoteLoad : a load operation requested on \"");
133 what+=reqNode->getName(); what+="\" with no container specified.";
134 reqNode->setErrorDetails(what);
135 throw Exception(what);
139 Engines::Container_var GetContainerObj(InlineNode *reqNode, bool& isStandardCont)
141 isStandardCont = false;
142 Container *container(reqNode->getContainer());
143 Engines::Container_var objContainer(Engines::Container::_nil());
145 throw YACS::Exception("No container specified !");
146 SalomeContainer *containerCast0(dynamic_cast<SalomeContainer *>(container));
147 SalomeHPContainer *containerCast1(dynamic_cast<SalomeHPContainer *>(container));
150 isStandardCont = true;
151 objContainer=containerCast0->getContainerPtr(reqNode);
153 else if(containerCast1)
155 YACS::BASES::AutoCppPtr<SalomeContainerTmpForHP> tmpCont(SalomeContainerTmpForHP::BuildFrom(containerCast1,reqNode));
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 !");
165 Engines::Container_var PythonEntry::loadPythonAdapter(InlineNode *reqNode, bool& isInitializeRequested)
167 bool isStandardCont(true);
168 Engines::Container_var objContainer(GetContainerObj(reqNode,isStandardCont));
169 isInitializeRequested=false;
172 Engines::PyNodeBase_var dftPyScript(retrieveDftRemotePyInterpretorIfAny(objContainer));
173 if(CORBA::is_nil(dftPyScript))
175 isInitializeRequested=!isStandardCont;
176 createRemoteAdaptedPyInterpretor(objContainer);
179 assignRemotePyInterpretor(dftPyScript);
181 catch( const SALOME::SALOME_Exception& ex )
183 std::string msg="Exception on remote python node creation ";
185 msg += ex.details.text.in();
186 reqNode->setErrorDetails(msg);
187 throw Exception(msg);
189 Engines::PyNodeBase_var pynode(getRemoteInterpreterHandle());
190 if(CORBA::is_nil(pynode))
191 throw Exception("In PythonNode the ref in NULL ! ");
195 void PythonEntry::loadRemoteContext(InlineNode *reqNode, Engines::Container_ptr objContainer, bool isInitializeRequested)
197 Container *container(reqNode->getContainer());
198 Engines::PyNodeBase_var pynode(getRemoteInterpreterHandle());
201 #if PY_VERSION_HEX < 0x03070000
202 std::unique_lock<std::mutex> lock(data_mutex);
205 const char *picklizeScript(getSerializationScript());
206 PyObject *res=PyRun_String(picklizeScript,Py_file_input,_context,_context);
207 PyObject *res2(PyRun_String(SCRIPT_FOR_SIMPLE_SERIALIZATION,Py_file_input,_context,_context));
208 if(res == NULL || res2==NULL)
210 std::string errorDetails;
211 PyObject* new_stderr = newPyStdOut(errorDetails);
212 reqNode->setErrorDetails(errorDetails);
213 PySys_SetObject((char*)"stderr", new_stderr);
215 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
216 Py_DECREF(new_stderr);
217 throw Exception("Error during load");
219 Py_DECREF(res); Py_DECREF(res2);
220 AutoPyRef res3(PyRun_String(SCRIPT_FOR_BIGOBJECT,Py_file_input,_context,_context));
221 _pyfuncSer=PyDict_GetItemString(_context,"pickleForDistPyth2009");
222 _pyfuncUnser=PyDict_GetItemString(_context,"unPickleForDistPyth2009");
223 _pyfuncSimpleSer=PyDict_GetItemString(_context,"pickleForVarSimplePyth2009");
224 if(! _pyClsBigObject )
226 _pyClsBigObject=PyDict_GetItemString(_context,"BigObjectOnDiskBase");
227 Py_INCREF(_pyClsBigObject);
229 if(_pyfuncSer == NULL)
231 std::string errorDetails;
232 PyObject *new_stderr(newPyStdOut(errorDetails));
233 reqNode->setErrorDetails(errorDetails);
234 PySys_SetObject((char*)"stderr", new_stderr);
236 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
237 Py_DECREF(new_stderr);
238 throw Exception("Error during load");
240 if(_pyfuncUnser == NULL)
242 std::string errorDetails;
243 PyObject *new_stderr(newPyStdOut(errorDetails));
244 reqNode->setErrorDetails(errorDetails);
245 PySys_SetObject((char*)"stderr", new_stderr);
247 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
248 Py_DECREF(new_stderr);
249 throw Exception("Error during load");
251 if(_pyfuncSimpleSer == NULL)
253 std::string errorDetails;
254 PyObject *new_stderr(newPyStdOut(errorDetails));
255 reqNode->setErrorDetails(errorDetails);
256 PySys_SetObject((char*)"stderr", new_stderr);
258 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
259 Py_DECREF(new_stderr);
260 throw Exception("Error during load");
263 if(isInitializeRequested)
264 {//This one is called only once at initialization in the container if an init-script is specified.
267 std::string zeInitScriptKey(container->getProperty(HomogeneousPoolContainer::INITIALIZE_SCRIPT_KEY));
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();
276 reqNode->setErrorDetails(msg);
277 throw Exception(msg);
279 DEBTRACE( "---------------End PyNode::loadRemote function---------------" );
283 std::string PythonEntry::GetContainerLog(const std::string& mode, Container *container, const Task *askingTask)
291 SalomeContainer *containerCast(dynamic_cast<SalomeContainer *>(container));
292 SalomeHPContainer *objContainer2(dynamic_cast<SalomeHPContainer *>(container));
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";
318 void PythonEntry::commonRemoteLoad(InlineNode *reqNode)
320 loadRemoteContainer(reqNode);
321 bool isInitializeRequested;
322 Engines::Container_var objContainer(loadPythonAdapter(reqNode,isInitializeRequested));
323 loadRemoteContext(reqNode,objContainer,isInitializeRequested);
326 bool PythonEntry::hasImposedResource()const
328 return !_imposedResource.empty() && !_imposedContainer.empty();
331 bool PythonEntry::IsProxy( PyObject *ob )
335 return PyObject_IsInstance( ob, _pyClsBigObject) == 1;
338 bool PythonEntry::GetDestroyStatus( PyObject *ob )
342 if( PyObject_IsInstance( ob, _pyClsBigObject) == 1 )
344 AutoPyRef unlinkOnDestructor = PyObject_GetAttrString(ob,"getDestroyStatus");
345 AutoPyRef tmp = PyObject_CallFunctionObjArgs(unlinkOnDestructor,nullptr);
346 if( PyBool_Check(tmp.get()) )
348 return tmp.get() == Py_True;
355 void PythonEntry::IfProxyDoSomething( PyObject *ob, const char *meth )
359 if( PyObject_IsInstance( ob, _pyClsBigObject) == 1 )
361 AutoPyRef unlinkOnDestructor = PyObject_GetAttrString(ob,meth);
362 AutoPyRef tmp = PyObject_CallFunctionObjArgs(unlinkOnDestructor,nullptr);
366 void PythonEntry::DoNotTouchFileIfProxy( PyObject *ob )
368 IfProxyDoSomething(ob,"doNotTouchFile");
371 void PythonEntry::UnlinkOnDestructorIfProxy( PyObject *ob )
373 IfProxyDoSomething(ob,"unlinkOnDestructor");
376 PythonNode::PythonNode(const PythonNode& other, ComposedNode *father):InlineNode(other,father),_autoSqueeze(other._autoSqueeze)
378 _pynode = Engines::PyScriptNode::_nil();
379 _implementation=IMPL_NAME;
382 _context=PyDict_New();
383 if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
386 msg << "Impossible to set builtins" << __FILE__ << ":" << __LINE__;
387 _errorDetails=msg.str();
388 throw Exception(msg.str());
393 PythonNode::PythonNode(const std::string& name):InlineNode(name)
395 _pynode = Engines::PyScriptNode::_nil();
396 _implementation=IMPL_NAME;
399 _context=PyDict_New();
400 if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
403 msg << "Impossible to set builtins" << __FILE__ << ":" << __LINE__;
404 _errorDetails=msg.str();
405 throw Exception(msg.str());
410 PythonNode::~PythonNode()
415 void PythonNode::checkBasicConsistency() const
417 DEBTRACE("checkBasicConsistency");
418 InlineNode::checkBasicConsistency();
422 res=Py_CompileString(_script.c_str(),getName().c_str(),Py_file_input);
425 std::string error="";
426 PyObject* new_stderr = newPyStdOut(error);
427 PySys_SetObject((char*)"stderr", new_stderr);
429 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
430 Py_DECREF(new_stderr);
431 throw Exception(error);
438 void PythonNode::load()
440 DEBTRACE( "---------------PyNode::load function---------------" );
441 if(_mode==PythonNode::REMOTE_NAME)
447 void PythonNode::loadLocal()
449 DEBTRACE( "---------------PyNode::loadLocal function---------------" );
453 void PythonNode::loadRemote()
455 commonRemoteLoad(this);
458 void PythonNode::execute()
460 if(_mode==PythonNode::REMOTE_NAME)
466 void PythonNode::executeRemote()
468 DEBTRACE( "++++++++++++++ PyNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
470 throw Exception("PythonNode badly loaded");
472 if(dynamic_cast<HomogeneousPoolContainer *>(getContainer()))
475 loadPythonAdapter(this,dummy);
476 _pynode->assignNewCompiledCode(getScript().c_str());
478 // not managed by unique_ptr here because destructed by the order of client.
479 SenderByteImpl *serializationInputCorba = nullptr;
480 AutoPyRef serializationInput;
482 #if PY_VERSION_HEX < 0x03070000
483 std::unique_lock<std::mutex> lock(data_mutex);
486 PyObject *args(0),*ob(0);
487 //===========================================================================
488 // Get inputs in input ports, build a Python dict and pickle it
489 //===========================================================================
491 std::list<InputPort *>::iterator iter2;
493 for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); ++iter2)
495 InputPyPort *p=(InputPyPort *)*iter2;
497 PyDict_SetItemString(args,p->getName().c_str(),ob);
501 PyObject_Print(args,stderr,Py_PRINT_RAW);
504 serializationInput.set(PyObject_CallFunctionObjArgs(_pyfuncSer,args,nullptr));
506 //The pickled string may contain NULL characters so use PyString_AsStringAndSize
507 char *serializationInputC(nullptr);
509 if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
510 throw Exception("DistributedPythonNode problem in python pickle");
511 // no copy here. The C byte array of Python is taken as this into CORBA sequence to avoid copy
512 serializationInputCorba = new SenderByteImpl(serializationInputC,len);
515 //get the list of output argument names
516 std::list<OutputPort *>::iterator iter;
517 Engines::listofstring myseq;
518 myseq.length(getNumberOfOutputPorts());
520 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); ++iter)
522 OutputPyPort *p=(OutputPyPort *)*iter;
523 myseq[pos]=p->getName().c_str();
524 DEBTRACE( "port name: " << p->getName() );
525 DEBTRACE( "port kind: " << p->edGetType()->kind() );
526 DEBTRACE( "port pos : " << pos );
529 //===========================================================================
530 // Execute in remote Python node
531 //===========================================================================
532 DEBTRACE( "-----------------starting remote python invocation-----------------" );
533 std::unique_ptr<SALOME::SenderByteSeq> resultCorba;
536 //pass outargsname and dict serialized
537 SALOME::SenderByte_var serializationInputRef = serializationInputCorba->_this();
538 _pynode->executeFirst(serializationInputRef);
539 //serializationInput and serializationInputCorba are no more needed for server. Release it.
540 serializationInput.set(nullptr);
541 resultCorba.reset( _pynode->executeSecond(myseq) );
543 catch( const SALOME::SALOME_Exception& ex )
545 std::ostringstream msg; msg << "Exception on remote python invocation" << std::endl << ex.details.text.in() << std::endl;
546 msg << "PyScriptNode CORBA ref : ";
548 CORBA::ORB_ptr orb(getSALOMERuntime()->getOrb());
549 if(!CORBA::is_nil(orb))
551 CORBA::String_var IOR(orb->object_to_string(_pynode));
556 _errorDetails=msg.str();
557 throw Exception(msg.str());
559 catch(CORBA::COMM_FAILURE& ex)
561 std::ostringstream msg;
562 msg << "Exception on remote python invocation." << std::endl ;
563 msg << "Caught system exception COMM_FAILURE -- unable to contact the "
564 << "object." << std::endl;
565 _errorDetails=msg.str();
566 throw Exception(msg.str());
568 catch(CORBA::SystemException& ex)
570 std::ostringstream msg;
571 msg << "Exception on remote python invocation." << std::endl ;
572 msg << "Caught a CORBA::SystemException." ;
575 CORBA::TypeCode_var tc = tmp.type();
576 const char *p = tc->name();
582 _errorDetails=msg.str();
583 throw Exception(msg.str());
585 catch(CORBA::Exception& ex)
587 std::ostringstream msg;
588 msg << "Exception on remote python invocation." << std::endl ;
589 msg << "Caught CORBA::Exception. " ;
592 CORBA::TypeCode_var tc = tmp.type();
593 const char *p = tc->name();
599 _errorDetails=msg.str();
600 throw Exception(msg.str());
602 catch(omniORB::fatalException& fe)
604 std::ostringstream msg;
605 msg << "Exception on remote python invocation." << std::endl ;
606 msg << "Caught omniORB::fatalException:" << std::endl;
607 msg << " file: " << fe.file() << std::endl;
608 msg << " line: " << fe.line() << std::endl;
609 msg << " mesg: " << fe.errmsg() << std::endl;
610 _errorDetails=msg.str();
611 throw Exception(msg.str());
613 DEBTRACE( "-----------------end of remote python invocation-----------------" );
614 //===========================================================================
615 // Get results, unpickle and put them in output ports
616 //===========================================================================
618 #if PY_VERSION_HEX < 0x03070000
619 std::unique_lock<std::mutex> lock(data_mutex);
622 DEBTRACE( "-----------------PythonNode::outputs-----------------" );
623 int nres( resultCorba->length() );
625 if(getNumberOfOutputPorts() != nres)
627 std::string msg="Number of output arguments : Mismatch between definition and execution";
629 throw Exception(msg);
634 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); ++iter)
636 OutputPyPort *p=(OutputPyPort *)*iter;
637 DEBTRACE( "port name: " << p->getName() );
638 DEBTRACE( "port kind: " << p->edGetType()->kind() );
639 DEBTRACE( "port pos : " << pos );
640 SALOME::SenderByte_var elt = (*resultCorba)[pos];
641 SeqByteReceiver recv(elt);
642 unsigned long length = 0;
643 char *resultCorbaC = recv.data(length);
645 AutoPyRef resultPython=PyMemoryView_FromMemory(resultCorbaC,length,PyBUF_READ);
646 AutoPyRef args = PyTuple_New(1);
647 PyTuple_SetItem(args,0,resultPython.retn());
648 AutoPyRef ob = PyObject_CallObject(_pyfuncUnser,args);
651 std::stringstream msg;
652 msg << "Conversion with pickle of output ports failed !";
653 msg << " : " << __FILE__ << ":" << __LINE__;
654 _errorDetails=msg.str();
655 throw YACS::ENGINE::ConversionException(msg.str());
657 UnlinkOnDestructorIfProxy(ob);
663 catch(ConversionException& ex)
665 _errorDetails=ex.what();
669 squeezeMemoryRemote();
672 if(!isUsingPythonCache())
676 Engines::Container_var cont(GetContainerObj(this,dummy));
677 cont->removePyScriptNode(getName().c_str());
679 DEBTRACE( "++++++++++++++ ENDOF PyNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
682 void PythonNode::ExecuteLocalInternal(const std::string& codeStr, PyObject *context, std::string& errorDetails)
685 DEBTRACE( "context refcnt: " << context->ob_refcnt );
686 std::ostringstream stream;
687 stream << "/tmp/PythonNode_";
689 AutoPyRef code=Py_CompileString(codeStr.c_str(), stream.str().c_str(), Py_file_input);
693 AutoPyRef new_stderr = newPyStdOut(errorDetails);
694 PySys_SetObject((char*)"stderr", new_stderr);
696 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
697 throw YACS::Exception("Error during execution");
700 AutoPyRef res = PyEval_EvalCode( code, context, context);
702 DEBTRACE( "context refcnt: " << context->ob_refcnt );
705 if(PyErr_Occurred ())
708 AutoPyRef new_stderr = newPyStdOut(errorDetails);
709 PySys_SetObject((char*)"stderr", new_stderr);
710 ofstream errorfile(stream.str().c_str());
711 if (errorfile.is_open())
713 errorfile << codeStr;
717 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
718 throw YACS::Exception("Error during execution");
722 void PythonNode::executeLocalInternal(const std::string& codeStr)
724 ExecuteLocalInternal(codeStr,_context,_errorDetails);
727 void PythonNode::executeLocal()
729 DEBTRACE( "++++++++++++++ PyNode::executeLocal: " << getName() << " ++++++++++++++++++++" );
732 std::ostringstream unpxy; unpxy << "from SALOME_PyNode import UnProxyObjectSimpleLocal" << std::endl;
733 DEBTRACE( "---------------PyNode::inputs---------------" );
734 list<InputPort *>::iterator iter2;
735 for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
737 InputPyPort *p=(InputPyPort *)*iter2;
738 DEBTRACE( "port name: " << p->getName() );
739 DEBTRACE( "port kind: " << p->edGetType()->kind() );
740 PyObject* ob=p->getPyObj();
741 DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
742 unpxy << p->getName() << " = UnProxyObjectSimpleLocal( " << p->getName() << " )" << std::endl;
744 PyObject_Print(ob,stderr,Py_PRINT_RAW);
747 int ier=PyDict_SetItemString(_context,p->getName().c_str(),ob);
748 DEBTRACE( "after PyDict_SetItemString:ob refcnt: " << ob->ob_refcnt );
751 DEBTRACE( "---------------End PyNode::inputs---------------" );
754 DEBTRACE( "----------------PyNode::calculation---------------" );
756 executeLocalInternal( unpxy.str() );
758 executeLocalInternal( _script );
760 DEBTRACE( "-----------------PyNode::outputs-----------------" );
761 list<OutputPort *>::iterator iter;
764 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
766 OutputPyPort *p=(OutputPyPort *)*iter;
767 DEBTRACE( "port name: " << p->getName() );
768 DEBTRACE( "port kind: " << p->edGetType()->kind() );
769 PyObject *ob=PyDict_GetItemString(_context,p->getName().c_str());
772 std::string msg="Error during execution: there is no variable ";
773 msg=msg+p->getName()+" in node context";
775 throw Exception(msg);
777 DEBTRACE( "PyNode::outputs::ob refcnt: " << ob->ob_refcnt );
779 PyObject_Print(ob,stderr,Py_PRINT_RAW);
783 if(!isUsingPythonCache())
784 PyDict_DelItemString(_context,p->getName().c_str());
787 catch(ConversionException& ex)
789 _errorDetails=ex.what();
794 DEBTRACE( "-----------------End PyNode::outputs-----------------" );
795 if(!isUsingPythonCache())
797 for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
799 AutoPyRef pStr = PyUnicode_FromString( (*iter2)->getName().c_str() );
800 if( PyDict_Contains(_context,pStr) == 1 )
801 { PyDict_DelItem(_context,pStr); }
805 DEBTRACE( "++++++++++++++ End PyNode::execute: " << getName() << " ++++++++++++++++++++" );
808 void PythonNode::squeezeMemorySafe()
811 if(_mode==PythonNode::REMOTE_NAME)
812 this->squeezeMemoryRemote();
814 this->squeezeMemory();
817 void PythonNode::squeezeMemory()
819 for(auto p : _setOfInputPort)
821 PyDict_DelItemString(_context,p->getName().c_str());
822 InputPyPort *p2(static_cast<InputPyPort *>(p));
823 if(p2->canSafelySqueezeMemory())
826 for(auto p : _setOfOutputPort)
828 PyDict_DelItemString(_context,p->getName().c_str());
829 OutputPyPort *p2(static_cast<OutputPyPort *>(p));
830 p2->putWithoutForward(Py_None);
834 void PythonNode::squeezeMemoryRemote()
836 for(auto p : _setOfInputPort)
838 InputPyPort *p2(static_cast<InputPyPort *>(p));
839 if(p2->canSafelySqueezeMemory())
842 for(auto p : _setOfOutputPort)
844 OutputPyPort *p2(static_cast<OutputPyPort *>(p));
845 p2->putWithoutForward(Py_None);
849 std::string PythonNode::getContainerLog()
851 return PythonEntry::GetContainerLog(_mode,_container,this);
854 void PythonNode::shutdown(int level)
856 DEBTRACE("PythonNode::shutdown " << level);
857 if(_mode=="local")return;
861 _container->shutdown(level);
865 void PythonNode::imposeResource(const std::string& resource_name,
866 const std::string& container_name)
868 if(!resource_name.empty() && !container_name.empty())
870 _imposedResource = resource_name;
871 _imposedContainer = container_name;
875 bool PythonNode::canAcceptImposedResource()
877 return _container != nullptr && _container->canAcceptImposedResource();
880 bool PythonNode::hasImposedResource()const
882 return PythonEntry::hasImposedResource();
885 std::string PythonNode::pythonEntryName()const
887 if(isUsingPythonCache())
888 return "DEFAULT_NAME_FOR_UNIQUE_PYTHON_NODE_ENTRY";
893 bool PythonNode::isUsingPythonCache()const
897 found = _container->isUsingPythonCache();
901 void PythonNode::freeKernelPynode()
903 if(!CORBA::is_nil(_pynode))
907 _pynode->UnRegister();
911 DEBTRACE("Trouble when pynode->UnRegister!")
913 _pynode = Engines::PyScriptNode::_nil();
917 Node *PythonNode::simpleClone(ComposedNode *father, bool editionOnly) const
919 return new PythonNode(*this,father);
922 void PythonNode::createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer)
925 _pynode=objContainer->createPyScriptNode(pythonEntryName().c_str(),getScript().c_str());
929 Engines::PyNodeBase_var PythonNode::retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const
931 Engines::PyScriptNode_var ret(objContainer->getDefaultPyScriptNode(pythonEntryName().c_str()));
932 if(!CORBA::is_nil(ret))
936 return Engines::PyNodeBase::_narrow(ret);
939 void PythonNode::assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp)
941 if(CORBA::is_nil(_pynode))
942 _pynode=Engines::PyScriptNode::_narrow(remoteInterp);
945 Engines::PyScriptNode_var tmpp(Engines::PyScriptNode::_narrow(remoteInterp));
946 if(!_pynode->_is_equivalent(tmpp))
949 _pynode=Engines::PyScriptNode::_narrow(remoteInterp);
952 _pynode->assignNewCompiledCode(getScript().c_str());
955 Engines::PyNodeBase_var PythonNode::getRemoteInterpreterHandle()
957 return Engines::PyNodeBase::_narrow(_pynode);
960 //! Create a new node of same type with a given name
961 PythonNode* PythonNode::cloneNode(const std::string& name)
963 PythonNode* n=new PythonNode(name);
964 n->setScript(_script);
965 list<InputPort *>::iterator iter;
966 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
968 InputPyPort *p=(InputPyPort *)*iter;
969 DEBTRACE( "port name: " << p->getName() );
970 DEBTRACE( "port kind: " << p->edGetType()->kind() );
971 n->edAddInputPort(p->getName(),p->edGetType());
973 list<OutputPort *>::iterator iter2;
974 for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
976 OutputPyPort *p=(OutputPyPort *)*iter2;
977 DEBTRACE( "port name: " << p->getName() );
978 DEBTRACE( "port kind: " << p->edGetType()->kind() );
979 n->edAddOutputPort(p->getName(),p->edGetType());
984 void PythonNode::applyDPLScope(ComposedNode *gfn)
986 std::vector< std::pair<std::string,int> > ret(getDPLScopeInfo(gfn));
993 std::size_t sz(ret.size());
995 for(std::size_t i=0;i<sz;i++)
997 const std::pair<std::string,int>& p(ret[i]);
998 PyObject *elt(PyTuple_New(2));
999 PyTuple_SetItem(elt,0,PyUnicode_FromString(p.first.c_str()));
1000 PyTuple_SetItem(elt,1,PyLong_FromLong(p.second));
1001 PyList_SetItem(ob,i,elt);
1004 if(_mode==REMOTE_NAME)
1006 Engines::pickledArgs_var serializationInputCorba(new Engines::pickledArgs);
1009 PyObject *serializationInput(PyObject_CallFunctionObjArgs(_pyfuncSimpleSer,ob,NULL));
1011 char *serializationInputC(0);
1013 if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
1014 throw Exception("DistributedPythonNode problem in python pickle");
1015 serializationInputCorba->length(len);
1016 for(int i=0; i < len ; i++)
1017 serializationInputCorba[i]=serializationInputC[i];
1018 Py_XDECREF(serializationInput);
1020 _pynode->defineNewCustomVar(DPL_INFO_NAME,serializationInputCorba);
1025 PyDict_SetItemString(_context,DPL_INFO_NAME,ob);
1030 PyFuncNode::PyFuncNode(const PyFuncNode& other, ComposedNode *father):InlineFuncNode(other,father),_pyfunc(0)
1032 _implementation = PythonNode::IMPL_NAME;
1035 _context=PyDict_New();
1036 DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
1037 if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
1040 msg << "Not possible to set builtins" << __FILE__ << ":" << __LINE__;
1041 _errorDetails=msg.str();
1042 throw Exception(msg.str());
1047 PyFuncNode::PyFuncNode(const std::string& name): InlineFuncNode(name),_pyfunc(0)
1050 _implementation = PythonNode::IMPL_NAME;
1051 DEBTRACE( "PyFuncNode::PyFuncNode " << name );
1054 _context=PyDict_New();
1055 DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
1056 if( PyDict_SetItemString( _context, "__builtins__", getSALOMERuntime()->getBuiltins() ))
1059 msg << "Not possible to set builtins" << __FILE__ << ":" << __LINE__;
1060 _errorDetails=msg.str();
1061 throw Exception(msg.str());
1066 PyFuncNode::~PyFuncNode()
1068 if(!CORBA::is_nil(_pynode))
1070 _pynode->UnRegister();
1074 void PyFuncNode::init(bool start)
1076 initCommonPartWithoutStateManagement(start);
1077 if(_state == YACS::DISABLED)
1079 exDisabledState(); // to refresh propagation of DISABLED state
1082 if(start) //complete initialization
1083 setState(YACS::READY);
1084 else if(_state > YACS::LOADED)// WARNING FuncNode has internal vars (CEA usecase) ! Partial initialization (inside a loop). Exclusivity of funcNode.
1085 setState(YACS::TORECONNECT);
1088 void PyFuncNode::checkBasicConsistency() const
1090 DEBTRACE("checkBasicConsistency");
1091 InlineFuncNode::checkBasicConsistency();
1095 res=Py_CompileString(_script.c_str(),getName().c_str(),Py_file_input);
1098 std::string error="";
1099 PyObject* new_stderr = newPyStdOut(error);
1100 PySys_SetObject((char*)"stderr", new_stderr);
1102 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1103 Py_DECREF(new_stderr);
1104 throw Exception(error);
1111 void PyFuncNode::load()
1113 DEBTRACE( "---------------PyfuncNode::load function---------------" );
1114 if(_mode==PythonNode::REMOTE_NAME)
1120 void PyFuncNode::loadRemote()
1122 commonRemoteLoad(this);
1125 void PyFuncNode::loadLocal()
1127 DEBTRACE( "---------------PyFuncNode::load function " << getName() << " ---------------" );
1128 DEBTRACE( _script );
1131 list<OutputPort *>::iterator iter;
1132 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
1134 OutputPyPort *p=(OutputPyPort *)*iter;
1135 DEBTRACE( "port name: " << p->getName() );
1136 DEBTRACE( "port kind: " << p->edGetType()->kind() );
1142 DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
1144 std::ostringstream stream;
1145 stream << "/tmp/PythonNode_";
1148 PyObject* code=Py_CompileString(_script.c_str(), stream.str().c_str(), Py_file_input);
1152 PyObject* new_stderr = newPyStdOut(_errorDetails);
1153 PySys_SetObject((char*)"stderr", new_stderr);
1155 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1156 Py_DECREF(new_stderr);
1157 throw Exception("Error during execution");
1159 PyObject *res = PyEval_EvalCode( code, _context, _context);
1163 DEBTRACE( "_context refcnt: " << _context->ob_refcnt );
1164 if(PyErr_Occurred ())
1167 PyObject* new_stderr = newPyStdOut(_errorDetails);
1168 PySys_SetObject((char*)"stderr", new_stderr);
1169 ofstream errorfile(stream.str().c_str());
1170 if (errorfile.is_open())
1172 errorfile << _script;
1176 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1177 Py_DECREF(new_stderr);
1178 throw Exception("Error during execution");
1181 _pyfunc=PyDict_GetItemString(_context,_fname.c_str());
1182 DEBTRACE( "_pyfunc refcnt: " << _pyfunc->ob_refcnt );
1186 PyObject* new_stderr = newPyStdOut(_errorDetails);
1187 PySys_SetObject((char*)"stderr", new_stderr);
1189 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1190 Py_DECREF(new_stderr);
1191 throw Exception("Error during execution");
1193 DEBTRACE( "---------------End PyFuncNode::load function---------------" );
1197 void PyFuncNode::execute()
1199 if(_mode==PythonNode::REMOTE_NAME)
1205 void PyFuncNode::executeRemote()
1207 DEBTRACE( "++++++++++++++ PyFuncNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
1209 throw Exception("DistributedPythonNode badly loaded");
1211 if(dynamic_cast<HomogeneousPoolContainer *>(getContainer()))
1214 loadPythonAdapter(this,dummy);
1215 _pynode->executeAnotherPieceOfCode(getScript().c_str());
1218 Engines::pickledArgs_var serializationInputCorba(new Engines::pickledArgs);;
1220 #if PY_VERSION_HEX < 0x03070000
1221 std::unique_lock<std::mutex> lock(data_mutex);
1225 //===========================================================================
1226 // Get inputs in input ports, build a Python tuple and pickle it
1227 //===========================================================================
1228 PyObject *args(PyTuple_New(getNumberOfInputPorts()));
1230 for(std::list<InputPort *>::iterator iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++,pos++)
1232 InputPyPort *p=(InputPyPort *)*iter2;
1235 PyTuple_SetItem(args,pos,ob);
1238 PyObject_Print(args,stderr,Py_PRINT_RAW);
1241 PyObject *serializationInput=PyObject_CallObject(_pyfuncSer,args);
1243 //The pickled string may contain NULL characters so use PyString_AsStringAndSize
1244 char *serializationInputC(0);
1246 if (PyBytes_AsStringAndSize(serializationInput, &serializationInputC, &len))
1247 throw Exception("DistributedPythonNode problem in python pickle");
1249 serializationInputCorba->length(len);
1250 for(int i=0; i < len ; i++)
1251 serializationInputCorba[i]=serializationInputC[i];
1252 Py_DECREF(serializationInput);
1255 //===========================================================================
1256 // Execute in remote Python node
1257 //===========================================================================
1258 DEBTRACE( "-----------------starting remote python invocation-----------------" );
1259 Engines::pickledArgs_var resultCorba;
1262 resultCorba=_pynode->execute(getFname().c_str(),serializationInputCorba);
1264 catch( const SALOME::SALOME_Exception& ex )
1266 std::string msg="Exception on remote python invocation";
1268 msg += ex.details.text.in();
1270 throw Exception(msg);
1272 catch(CORBA::COMM_FAILURE& ex)
1274 std::ostringstream msg;
1275 msg << "Exception on remote python invocation." << std::endl ;
1276 msg << "Caught system exception COMM_FAILURE -- unable to contact the "
1277 << "object." << std::endl;
1278 _errorDetails=msg.str();
1279 throw Exception(msg.str());
1281 catch(CORBA::SystemException& ex)
1283 std::ostringstream msg;
1284 msg << "Exception on remote python invocation." << std::endl ;
1285 msg << "Caught a CORBA::SystemException." ;
1288 CORBA::TypeCode_var tc = tmp.type();
1289 const char *p = tc->name();
1295 _errorDetails=msg.str();
1296 throw Exception(msg.str());
1298 catch(CORBA::Exception& ex)
1300 std::ostringstream msg;
1301 msg << "Exception on remote python invocation." << std::endl ;
1302 msg << "Caught CORBA::Exception. " ;
1305 CORBA::TypeCode_var tc = tmp.type();
1306 const char *p = tc->name();
1312 _errorDetails=msg.str();
1313 throw Exception(msg.str());
1315 catch(omniORB::fatalException& fe)
1317 std::ostringstream msg;
1318 msg << "Exception on remote python invocation." << std::endl ;
1319 msg << "Caught omniORB::fatalException:" << std::endl;
1320 msg << " file: " << fe.file() << std::endl;
1321 msg << " line: " << fe.line() << std::endl;
1322 msg << " mesg: " << fe.errmsg() << std::endl;
1323 _errorDetails=msg.str();
1324 throw Exception(msg.str());
1326 DEBTRACE( "-----------------end of remote python invocation-----------------" );
1327 //===========================================================================
1328 // Get results, unpickle and put them in output ports
1329 //===========================================================================
1330 char *resultCorbaC=new char[resultCorba->length()+1];
1331 resultCorbaC[resultCorba->length()]='\0';
1332 for(int i=0;i<resultCorba->length();i++)
1333 resultCorbaC[i]=resultCorba[i];
1336 #if PY_VERSION_HEX < 0x03070000
1337 std::unique_lock<std::mutex> lock(data_mutex);
1341 PyObject *resultPython(PyBytes_FromStringAndSize(resultCorbaC,resultCorba->length()));
1342 delete [] resultCorbaC;
1343 PyObject *args(PyTuple_New(1)),*ob(0);
1344 PyTuple_SetItem(args,0,resultPython);
1345 PyObject *finalResult=PyObject_CallObject(_pyfuncUnser,args);
1348 DEBTRACE( "-----------------PythonNode::outputs-----------------" );
1350 if(finalResult == Py_None)
1352 else if(PyTuple_Check(finalResult))
1353 nres=PyTuple_Size(finalResult);
1355 if(getNumberOfOutputPorts() != nres)
1357 std::string msg="Number of output arguments : Mismatch between definition and execution";
1358 Py_DECREF(finalResult);
1360 throw Exception(msg);
1366 for(std::list<OutputPort *>::iterator iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++, pos++)
1368 OutputPyPort *p=(OutputPyPort *)*iter;
1369 DEBTRACE( "port name: " << p->getName() );
1370 DEBTRACE( "port kind: " << p->edGetType()->kind() );
1371 DEBTRACE( "port pos : " << pos );
1372 if(PyTuple_Check(finalResult))
1373 ob=PyTuple_GetItem(finalResult,pos) ;
1376 DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1379 Py_DECREF(finalResult);
1381 catch(ConversionException& ex)
1383 Py_DECREF(finalResult);
1384 _errorDetails=ex.what();
1389 DEBTRACE( "++++++++++++++ ENDOF PyFuncNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
1392 void PyFuncNode::executeLocal()
1394 DEBTRACE( "++++++++++++++ PyFuncNode::execute: " << getName() << " ++++++++++++++++++++" );
1398 if(!_pyfunc)throw Exception("PyFuncNode badly loaded");
1401 DEBTRACE( "---------------PyFuncNode::inputs---------------" );
1402 PyObject* args = PyTuple_New(getNumberOfInputPorts()) ;
1403 list<InputPort *>::iterator iter2;
1404 for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
1406 InputPyPort *p=(InputPyPort *)*iter2;
1407 DEBTRACE( "port name: " << p->getName() );
1408 DEBTRACE( "port kind: " << p->edGetType()->kind() );
1411 PyObject_Print(ob,stderr,Py_PRINT_RAW);
1414 DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1416 PyTuple_SetItem(args,pos,ob);
1417 DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1420 DEBTRACE( "---------------End PyFuncNode::inputs---------------" );
1422 DEBTRACE( "----------------PyFuncNode::calculation---------------" );
1424 PyObject_Print(_pyfunc,stderr,Py_PRINT_RAW);
1426 PyObject_Print(args,stderr,Py_PRINT_RAW);
1429 DEBTRACE( "_pyfunc refcnt: " << _pyfunc->ob_refcnt );
1430 PyObject* result = PyObject_CallObject( _pyfunc , args ) ;
1431 DEBTRACE( "_pyfunc refcnt: " << _pyfunc->ob_refcnt );
1438 PyObject* new_stderr = newPyStdOut(_errorDetails);
1439 PySys_SetObject((char*)"stderr", new_stderr);
1440 std::ostringstream stream;
1441 stream << "/tmp/PythonNode_";
1443 ofstream errorfile(stream.str().c_str());
1444 if (errorfile.is_open())
1446 errorfile << _script;
1450 PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
1451 Py_DECREF(new_stderr);
1452 throw Exception("Error during execution");
1454 DEBTRACE( "----------------End PyFuncNode::calculation---------------" );
1456 DEBTRACE( "-----------------PyFuncNode::outputs-----------------" );
1458 if(result == Py_None)
1460 else if(PyTuple_Check(result))
1461 nres=PyTuple_Size(result);
1463 if(getNumberOfOutputPorts() != nres)
1465 std::string msg="Number of output arguments : Mismatch between definition and execution";
1468 throw Exception(msg);
1473 PyObject_Print(result,stderr,Py_PRINT_RAW);
1476 list<OutputPort *>::iterator iter;
1479 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
1481 OutputPyPort *p=(OutputPyPort *)*iter;
1482 DEBTRACE( "port name: " << p->getName() );
1483 DEBTRACE( "port kind: " << p->edGetType()->kind() );
1484 DEBTRACE( "port pos : " << pos );
1485 if(PyTuple_Check(result))ob=PyTuple_GetItem(result,pos) ;
1487 DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
1489 PyObject_Print(ob,stderr,Py_PRINT_RAW);
1496 catch(ConversionException& ex)
1499 _errorDetails=ex.what();
1502 DEBTRACE( "-----------------End PyFuncNode::outputs-----------------" );
1505 DEBTRACE( "++++++++++++++ End PyFuncNode::execute: " << getName() << " ++++++++++++++++++++" );
1508 Node *PyFuncNode::simpleClone(ComposedNode *father, bool editionOnly) const
1510 return new PyFuncNode(*this,father);
1513 void PyFuncNode::createRemoteAdaptedPyInterpretor(Engines::Container_ptr objContainer)
1515 if(!CORBA::is_nil(_pynode))
1516 _pynode->UnRegister();
1517 _pynode=objContainer->createPyNode(getName().c_str(),getScript().c_str());
1520 Engines::PyNodeBase_var PyFuncNode::retrieveDftRemotePyInterpretorIfAny(Engines::Container_ptr objContainer) const
1522 Engines::PyNode_var ret(objContainer->getDefaultPyNode(getName().c_str()));
1523 if(!CORBA::is_nil(ret))
1527 return Engines::PyNodeBase::_narrow(ret);
1530 void PyFuncNode::assignRemotePyInterpretor(Engines::PyNodeBase_var remoteInterp)
1532 if(!CORBA::is_nil(_pynode))
1534 Engines::PyNode_var tmpp(Engines::PyNode::_narrow(remoteInterp));
1535 if(_pynode->_is_equivalent(tmpp))
1538 if(!CORBA::is_nil(_pynode))
1539 _pynode->UnRegister();
1540 _pynode=Engines::PyNode::_narrow(remoteInterp);
1543 Engines::PyNodeBase_var PyFuncNode::getRemoteInterpreterHandle()
1545 return Engines::PyNodeBase::_narrow(_pynode);
1548 //! Create a new node of same type with a given name
1549 PyFuncNode* PyFuncNode::cloneNode(const std::string& name)
1551 PyFuncNode* n=new PyFuncNode(name);
1552 n->setScript(_script);
1553 n->setFname(_fname);
1554 list<InputPort *>::iterator iter;
1555 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
1557 InputPyPort *p=(InputPyPort *)*iter;
1558 n->edAddInputPort(p->getName(),p->edGetType());
1560 list<OutputPort *>::iterator iter2;
1561 for(iter2 = _setOfOutputPort.begin(); iter2 != _setOfOutputPort.end(); iter2++)
1563 OutputPyPort *p=(OutputPyPort *)*iter2;
1564 n->edAddOutputPort(p->getName(),p->edGetType());
1569 std::string PyFuncNode::getContainerLog()
1571 return PythonEntry::GetContainerLog(_mode,_container,this);
1574 void PyFuncNode::shutdown(int level)
1576 DEBTRACE("PyFuncNode::shutdown " << level);
1577 if(_mode=="local")return;
1580 if(!CORBA::is_nil(_pynode)) _pynode->UnRegister();
1581 _pynode=Engines::PyNode::_nil();
1582 _container->shutdown(level);
1586 void PyFuncNode::imposeResource(const std::string& resource_name,
1587 const std::string& container_name)
1589 if(!resource_name.empty() && !container_name.empty())
1591 _imposedResource = resource_name;
1592 _imposedContainer = container_name;
1596 bool PyFuncNode::canAcceptImposedResource()
1598 return _container != nullptr && _container->canAcceptImposedResource();
1601 bool PyFuncNode::hasImposedResource()const
1603 return PythonEntry::hasImposedResource();