32 using namespace YACS::ENGINE;
 
   62   bool isContAlreadyStarted(
false);
 
   71         msg << 
"Impossible to set builtins" << __FILE__ << 
":" << __LINE__;
 
   75     const char picklizeScript[]=
"import cPickle\ndef pickleForDistPyth2009(*args,**kws):\n  return cPickle.dumps((args,kws),-1)\n\ndef unPickleForDistPyth2009(st):\n  args=cPickle.loads(st)\n  return args\n";
 
   81         PySys_SetObject((
char*)
"stderr", new_stderr);
 
   83         PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
 
   84         Py_DECREF(new_stderr);
 
   85         throw Exception(
"Error during execution");
 
   95         PySys_SetObject((
char*)
"stderr", new_stderr);
 
   97         PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
 
   98         Py_DECREF(new_stderr);
 
   99         throw Exception(
"Error during execution");
 
  105         PySys_SetObject((
char*)
"stderr", new_stderr);
 
  107         PySys_SetObject((
char*)
"stderr", PySys_GetObject((
char*)
"__stderr__"));
 
  108         Py_DECREF(new_stderr);
 
  109         throw Exception(
"Error during execution");
 
  112     Engines::Container_var objContainer=Engines::Container::_nil();
 
  114       throw Exception(
"No container specified !");
 
  119     else if(containerCast1)
 
  125       throw Exception(
"Unrecognized type of container ! Salome one is expected !");
 
  126     if(CORBA::is_nil(objContainer))
 
  127       throw Exception(
"Container corba pointer is NULL !");
 
  131         if(containerCast0 || !isContAlreadyStarted)
 
  137             Engines::PyNode_var dftPyScript(objContainer->getDefaultPyNode(
getName().c_str()));
 
  138             if(CORBA::is_nil(dftPyScript))
 
  144     catch( 
const SALOME::SALOME_Exception& ex )
 
  146         std::string msg=
"Exception on remote python node creation ";
 
  148         msg += ex.details.text.in();
 
  154       throw Exception(
"In DistributedPythonNode the ref in NULL ! ");
 
  157     DEBTRACE( 
"---------------End PyfuncSerNode::load function---------------" );
 
  163   YACSTRACE(1,
"+++++++++++++++++ DistributedPythonNode::execute: " << 
getName() << 
" " << 
getFname() << 
" +++++++++++++++++" );
 
  167     throw Exception(
"DistributedPythonNode badly loaded");
 
  168   Engines::pickledArgs *serializationInputCorba(0);
 
  173     DEBTRACE( 
"---------------DistributedPythonNode::inputs---------------" );
 
  181         PyTuple_SetItem(args,pos,ob);
 
  183     PyObject *serializationInput=PyObject_CallObject(
_pyfuncSer,args);
 
  184     std::string serializationInputC=PyString_AsString(serializationInput);
 
  185     serializationInputCorba=
new Engines::pickledArgs;
 
  186     int len=serializationInputC.length();
 
  187     serializationInputCorba->length(serializationInputC.length());
 
  188     for(
int i=0;
i<serializationInputC.length();
i++)
 
  189       (*serializationInputCorba)[
i]=serializationInputC[
i];
 
  190     Py_DECREF(serializationInput);
 
  193   DEBTRACE( 
"-----------------DistributedPythonNode starting remote python invocation-----------------" );
 
  194   Engines::pickledArgs *resultCorba;
 
  197       resultCorba=
_pynode->execute(
getFname().c_str(),*serializationInputCorba);
 
  201       std::string msg=
"Exception on remote python invocation";
 
  205   DEBTRACE( 
"-----------------DistributedPythonNode end of remote python invocation-----------------" );
 
  207   delete serializationInputCorba;
 
  208   char *resultCorbaC=
new char[resultCorba->length()+1];
 
  209   resultCorbaC[resultCorba->length()]=
'\0';
 
  210   for(
int i=0;
i<resultCorba->length();
i++)
 
  211     resultCorbaC[
i]=(*resultCorba)[
i];
 
  215     args = PyTuple_New(1);
 
  216     PyObject* resultPython=PyString_FromString(resultCorbaC);
 
  217     delete [] resultCorbaC;
 
  218     PyTuple_SetItem(args,0,resultPython);
 
  219     PyObject *finalResult=PyObject_CallObject(
_pyfuncUnser,args);
 
  220     DEBTRACE( 
"-----------------DistributedPythonNode::outputs-----------------" );
 
  222     if(finalResult == Py_None)
 
  224     else if(PyTuple_Check(finalResult))
 
  225       nres=PyTuple_Size(finalResult);
 
  229         std::string msg=
"Number of output arguments : Mismatch between definition and execution";
 
  230         Py_DECREF(finalResult);
 
  243             if(PyTuple_Check(finalResult))ob=PyTuple_GetItem(finalResult,pos) ;
 
  245             DEBTRACE( 
"ob refcnt: " << ob->ob_refcnt );
 
  251         Py_DECREF(finalResult);
 
  256   DEBTRACE( 
"++++++++++++++ End DistributedPythonNode::execute: " << 
getName() << 
" ++++++++++++++++++++" );
 
  288       DEBTRACE( 
"An exception was thrown!" );
 
  289       DEBTRACE( 
"The raised exception is of Type:" << exc->_name() );
 
  291       CORBA::SystemException* sysexc;
 
  292       sysexc=CORBA::SystemException::_downcast(exc);
 
  296           DEBTRACE( 
"minor code: " << sysexc->minor() );
 
  297           DEBTRACE( 
"completion code: " << sysexc->completed() );
 
  298           std::string text=
"Execution problem: ";
 
  299           std::string excname=sysexc->_name();
 
  300           if(excname == 
"BAD_OPERATION")
 
  302               text=text+
"bad operation detected";
 
  304           else if(excname == 
"MARSHAL" && sysexc->minor() == omni::MARSHAL_PassEndOfMessage)
 
  306               text=text+
"probably an error in arguments of service '" + method + 
"' from component '" +ref+ 
"'";
 
  308           else if(excname == 
"COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_UnMarshalResults)
 
  310               text=text+
"probably an error in output arguments of service '" + method + 
"' from component '" +ref+ 
"'";
 
  312           else if(excname == 
"COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_UnMarshalArguments)
 
  314               text=text+
"probably an error in input arguments of service '" + method + 
"' from component '" +ref+ 
"'";
 
  316           else if(excname == 
"COMM_FAILURE" && sysexc->minor() == omni::COMM_FAILURE_WaitingForReply)
 
  318               text=text+
"probably an error in input arguments of service '" + method + 
"' from component '" +ref+ 
"'";
 
  322               DEBTRACE(sysexc->NP_minorString() );
 
  323               text=text+
"System Exception "+ excname;
 
  330       CORBA::UnknownUserException* userexc;
 
  331       userexc=CORBA::UnknownUserException::_downcast(exc);
 
  334           CORBA::Any anyExcept = userexc->exception(); 
 
  336           const SALOME::SALOME_Exception* salexc;
 
  337           if(anyExcept >>= salexc)
 
  339               DEBTRACE(
"SALOME_Exception: "<< salexc->details.sourceFile);
 
  340               DEBTRACE(
"SALOME_Exception: "<<salexc->details.lineNumber);
 
  344           std::string msg=
"Execution problem: User Exception occurred";
 
  348       std::string msg=
"Execution problem";