Salome HOME
PR: embedded container C++ & Python
authorprascle <prascle>
Wed, 18 May 2005 09:48:26 +0000 (09:48 +0000)
committerprascle <prascle>
Wed, 18 May 2005 09:48:26 +0000 (09:48 +0000)
13 files changed:
bin/runSalome.py
src/Container/Container_i.cxx
src/Container/Container_init_python.cxx [new file with mode: 0644]
src/Container/Container_init_python.hxx [new file with mode: 0644]
src/Container/Makefile.in
src/Container/SALOME_Container.cxx
src/LifeCycleCORBA/Launchers.cxx
src/SALOMEGUI/PyInterp_PyQt.cxx
src/SALOMEGUI/PyInterp_base.cxx
src/SALOMEGUI/PyInterp_base.h
src/SALOMEGUI/QAD_PyInterp.cxx
src/Session/SALOME_Session_Server.cxx
src/TestContainer/TestContainer.cxx

index 055268c56ccc5f976f3a529c982d50a8059e4263..1c47d008a761dacc0d97126b2336a4b86eec7b28 100755 (executable)
@@ -564,23 +564,6 @@ def startSalome(args, modules_list, modules_root_dir):
     myCmServer.setpath(modules_list,modules_root_dir)
     myCmServer.run()
 
-    #
-    # Lancement Session Server
-    #
-
-    mySessionServ = SessionServer(args)
-    mySessionServ.setpath(modules_list,modules_root_dir)
-    mySessionServ.run()
-
-    #macomm2=['ddd']
-    #pid = os.spawnvp(os.P_NOWAIT, macomm2[0], macomm2)
-    #
-    # Attente de la disponibilite du Session Server dans le Naming Service
-    #
-
-    import SALOME
-    session=clt.waitNS("/Kernel/Session",SALOME.Session)
-
     from Utils_Identity import getShortHostName
     
     if os.getenv("HOSTNAME") == None:
@@ -623,6 +606,23 @@ def startSalome(args, modules_list, modules_root_dir):
         myServer.run()
         clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer")
 
+    #
+    # Lancement Session Server
+    #
+
+    mySessionServ = SessionServer(args)
+    mySessionServ.setpath(modules_list,modules_root_dir)
+    mySessionServ.run()
+
+    #macomm2=['ddd']
+    #pid = os.spawnvp(os.P_NOWAIT, macomm2[0], macomm2)
+    #
+    # Attente de la disponibilite du Session Server dans le Naming Service
+    #
+
+    import SALOME
+    session=clt.waitNS("/Kernel/Session",SALOME.Session)
+
     end_time = os.times()
     print
     print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
index c2c346cc2f5b6231a3d9d2987532fee4bead80fd..f6374609ab258d4e596337448bb21307b67d3792 100644 (file)
@@ -38,6 +38,7 @@
 #include <dlfcn.h>
 #include <unistd.h>
 #include <Python.h>
+#include "Container_init_python.hxx"
 
 #include "utilities.h"
 using namespace std;
@@ -56,22 +57,23 @@ extern "C" {void ActSigIntHandler() ; }
 extern "C" {void SigIntHandler(int, siginfo_t *, void *) ; }
 
 
-static PyMethodDef MethodPyVoidMethod[] = {{ NULL, NULL }};
-PyThreadState *gtstate;
+// static PyMethodDef MethodPyVoidMethod[] = {{ NULL, NULL }};
+// PyThreadState *gtstate;
 
-void init_python(int argc, char **argv)
-{
-  if (gtstate)
-    return;
-  Py_SetProgramName(argv[0]);
-  Py_Initialize(); // Initialize the interpreter
-  PySys_SetArgv(argc, argv);
-  PyEval_InitThreads(); // Create (and acquire) the interpreter lock
-  Py_InitModule( "InitPyRunMethod" , MethodPyVoidMethod ) ;
-  //PyOS_setsig(SIGSEGV,&Handler);
-  //PyOS_setsig(SIGINT,&Handler);
-  gtstate = PyEval_SaveThread(); // Release the global thread state
-}
+// void init_python(int argc, char **argv)
+// {
+//   if (gtstate)
+//     return;
+//   Py_SetProgramName(argv[0]);
+//   Py_Initialize(); // Initialize the interpreter
+//   PySys_SetArgv(argc, argv);
+//   PyEval_InitThreads(); // Create (and acquire) the interpreter lock
+//   Py_InitModule( "InitPyRunMethod" , MethodPyVoidMethod ) ;
+//   //PyOS_setsig(SIGSEGV,&Handler);
+//   //PyOS_setsig(SIGINT,&Handler);
+//   gtstate = PyEval_SaveThread(); // Release the global thread state
+//   SCRUTE(gtstate);
+// }
 
 const char *Engines_Container_i::_defaultContainerName="FactoryServer";
 map<std::string, int> Engines_Container_i::_cntInstances_map;
@@ -164,18 +166,17 @@ Engines_Container_i::Engines_Container_i (CORBA::ORB_ptr orb,
       // import SALOME_Container
       // pycont = SALOME_Container.SALOME_Container_i(containerIORStr)
     
-      init_python(argc,argv);
-
       CORBA::String_var sior =  _orb->object_to_string(pCont);
       string myCommand="pyCont = SALOME_Container.SALOME_Container_i('";
       myCommand += sior;
       myCommand += "')\n";
       SCRUTE(myCommand);
 
-      PyEval_RestoreThread(gtstate);
+      SCRUTE(KERNEL_PYTHON::_gtstate);
+      PyEval_RestoreThread(KERNEL_PYTHON::_gtstate);
       PyRun_SimpleString("import SALOME_Container\n");
       PyRun_SimpleString((char*)myCommand.c_str());
-      PyEval_ReleaseThread(gtstate);
+      PyEval_ReleaseThread(KERNEL_PYTHON::_gtstate);
     }
 }
 
@@ -301,17 +302,19 @@ Engines_Container_i::load_component_Library(const char* componentName)
       INFOS("Can't load shared library : " << impl_name);
       INFOS("error dlopen: " << dlerror());
     }
-    _numInstanceMutex.unlock();
+  _numInstanceMutex.unlock();
 
   // --- try import Python component
 
+  INFOS("try import Python component "<<componentName);
   if (_library_map[aCompName])
     {
       return true; // Python Component, already imported
     }
   else
     {
-      PyEval_RestoreThread(gtstate);
+      SCRUTE(KERNEL_PYTHON::_gtstate);
+      PyEval_RestoreThread(KERNEL_PYTHON::_gtstate);
       PyObject *mainmod = PyImport_AddModule("__main__");
       PyObject *globals = PyModule_GetDict(mainmod);
       PyObject *pyCont = PyDict_GetItemString(globals, "pyCont");
@@ -320,7 +323,7 @@ Engines_Container_i::load_component_Library(const char* componentName)
                                             "s",componentName);
       int ret= PyInt_AsLong(result);
       SCRUTE(ret);
-      PyEval_ReleaseThread(gtstate);
+      PyEval_ReleaseThread(KERNEL_PYTHON::_gtstate);
   
       if (ret) // import possible: Python component
        {
@@ -370,7 +373,8 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName,
       string component_registerName =
        _containerName + "/" + instanceName;
 
-      PyEval_RestoreThread(gtstate);
+      SCRUTE(KERNEL_PYTHON::_gtstate);
+      PyEval_RestoreThread(KERNEL_PYTHON::_gtstate);
       PyObject *mainmod = PyImport_AddModule("__main__");
       PyObject *globals = PyModule_GetDict(mainmod);
       PyObject *pyCont = PyDict_GetItemString(globals, "pyCont");
@@ -382,7 +386,7 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName,
                                             studyId);
       string iors = PyString_AsString(result);
       SCRUTE(iors);
-      PyEval_ReleaseThread(gtstate);
+      PyEval_ReleaseThread(KERNEL_PYTHON::_gtstate);
   
       CORBA::Object_var obj = _orb->string_to_object(iors.c_str());
       iobject = Engines::Component::_narrow( obj ) ;
diff --git a/src/Container/Container_init_python.cxx b/src/Container/Container_init_python.cxx
new file mode 100644 (file)
index 0000000..1aac1d0
--- /dev/null
@@ -0,0 +1,56 @@
+//  SALOME Container : implementation of container and engine for Kernel
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : Container_init_python.cxx
+//  Author : Paul RASCLE, EDF
+//  Module : KERNEL
+//  $Header$
+
+#include "Container_init_python.hxx"
+
+#include "utilities.h"
+using namespace std;
+
+PyThreadState *KERNEL_PYTHON::_gtstate = 0;
+PyObject *KERNEL_PYTHON::salome_shared_modules_module = NULL;
+
+void KERNEL_PYTHON::init_python(int argc, char **argv)
+{
+  if (Py_IsInitialized())
+    {
+      MESSAGE("Python already initialized");
+      SCRUTE(KERNEL_PYTHON::_gtstate);
+      return;
+    }
+  MESSAGE("=================================================================");
+  MESSAGE("Python Initialization...");
+  MESSAGE("=================================================================");
+  Py_SetProgramName(argv[0]);
+  Py_Initialize(); // Initialize the interpreter
+  PySys_SetArgv(argc, argv);
+  PyEval_InitThreads(); // Create (and acquire) the interpreter lock
+  ASSERT(!KERNEL_PYTHON::_gtstate);
+  KERNEL_PYTHON::_gtstate = PyEval_SaveThread(); // Release global thread state
+  SCRUTE(KERNEL_PYTHON::_gtstate);
+}
+
diff --git a/src/Container/Container_init_python.hxx b/src/Container/Container_init_python.hxx
new file mode 100644 (file)
index 0000000..c28e99c
--- /dev/null
@@ -0,0 +1,44 @@
+//  SALOME Container : implementation of container and engine for Kernel
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : Container_init_python.hxx
+//  Author : Paul RASCLE, EDF
+//  Module : KERNEL
+//  $Header$
+
+#ifndef _CONTAINER_INIT_PYTHON_HXX_
+#define _CONTAINER_INIT_PYTHON_HXX_
+
+#include <pthread.h>  // must be before Python.h !
+#include <Python.h>
+
+struct  KERNEL_PYTHON
+{
+  static PyThreadState *_gtstate;
+  static PyObject *salome_shared_modules_module;
+
+  static void init_python(int argc, char **argv);
+
+};
+
+#endif
index 7098ace1516fea8440a17bca12e5045031642b33..5ccebde83945342646b59f1c2e0dd23ab3a85e1c 100644 (file)
@@ -41,12 +41,17 @@ EXPORT_PYSCRIPTS = SALOME_ComponentPy.py \
 EXPORT_HEADERS = \
        SALOME_Component_i.hxx \
        SALOME_Container_i.hxx \
-       SALOME_ContainerManager.hxx
+       SALOME_ContainerManager.hxx \
+       Container_init_python.hxx
 
 # Libraries targets
 
 LIB = libSalomeContainer.la 
-LIB_SRC = Component_i.cxx  Container_i.cxx SALOME_ContainerManager.cxx
+LIB_SRC = Component_i.cxx \
+         Container_i.cxx \
+         SALOME_ContainerManager.cxx \
+         Container_init_python.cxx
+
 LIB_SERVER_IDL = SALOME_Registry.idl SALOME_Component.idl SALOME_ContainerManager.idl
 LIB_CLIENT_IDL = 
 
index bd7d8539bb5fea6eff914be5dd7a279376e4e6fd..bce0641a230d9244b23e2ce7bd1376f79749c2e2 100644 (file)
@@ -48,6 +48,7 @@
 #endif
 
 #include <Python.h>
+#include "Container_init_python.hxx"
 
 using namespace std;
 
@@ -64,6 +65,10 @@ int main(int argc, char* argv[])
   SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
   INFOS_COMPILATION;
   BEGIN_OF(argv[0]);
+
+  int _argc = 1;
+  char* _argv[] = {""};
+  KERNEL_PYTHON::init_python(_argc,_argv);
   
   try{
     // Obtain a reference to the root POA.
index f3622465d3261f2cc78a1b8de31d99ed0f274f23..3957e8f77988af687633cde01ac26962860112df 100644 (file)
@@ -1,4 +1,7 @@
 #include <Launchers.hxx>
+#include "utilities.h"
+
+using namespace std;
 
 static int Launchers_IsLoaded = 0;
 static PyObject * Launchers_module = 0;
@@ -30,8 +33,14 @@ void releaseMainThread(PyThreadState *tstate){
 }
 
 void Launchers_assertInitialized() {
+  MESSAGE("===========================================================");
+  MESSAGE("Launchers_assertInitialized");
+  MESSAGE("===========================================================");
    PyThreadState *_save; 
    if( !Py_IsInitialized() ) {
+     MESSAGE("===========================================================");
+     MESSAGE("Py_Initialize()");
+     MESSAGE("===========================================================");
          Py_Initialize();
          PyEval_InitThreads();
          PyEval_SaveThread();
index 29077ca0e87b8e128bcb5011a267f8df2f67f194..6c33ce846cf549453ddda4f6662328cbadf86737 100644 (file)
@@ -10,6 +10,7 @@
 //  $Header$
 
 #include "PyInterp_PyQt.h" // this include must be first (see PyInterp_base.h)!
+#include "Container_init_python.hxx"
 #include "utilities.h"
 
 using namespace std;
@@ -35,8 +36,8 @@ void PyInterp_PyQt::initState()
   * The GIL is acquired in initState and will be held on initState exit
   * It is the caller responsability to release the lock on exit if needed
   */
-  SCRUTE(PyInterp_base::_gtstate);
-  _tstate=PyInterp_base::_gtstate;
+  SCRUTE(KERNEL_PYTHON::_gtstate);
+  _tstate=KERNEL_PYTHON::_gtstate;
   PyEval_AcquireLock();
   PyThreadState_Swap(_tstate);
   SCRUTE(_tstate);
index 1c4879d1d46d7e1b037c61bf22521350c4bd7b9b..844bc854576a07e43f1ec272bfa8df3ae21fe29d 100644 (file)
@@ -14,6 +14,7 @@
 #include <vector>
 
 #include "PyInterp_base.h" // this include must be first (see PyInterp_base.h)!
+#include "Container_init_python.hxx"
 #include <cStringIO.h>
 
 #include <qmutex.h>
@@ -25,8 +26,8 @@ using namespace std;
 
 
 #ifdef _DEBUG_
-static int MYDEBUG = 0;
-static int MYPYDEBUG = 0;
+static int MYDEBUG = 1;
+static int MYPYDEBUG = 1;
 #else
 static int MYDEBUG = 0;
 static int MYPYDEBUG = 0;
@@ -38,7 +39,8 @@ static QMutex myMutex(true);
 
 PyLockWrapper::PyLockWrapper(PyThreadState* theThreadState): 
   myThreadState(theThreadState),
-  mySaveThreadState(PyInterp_base::_gtstate)
+  //mySaveThreadState(PyInterp_base::_gtstate)
+  mySaveThreadState(KERNEL_PYTHON::_gtstate)
 {
   PyEval_AcquireLock();
   mySaveThreadState = PyThreadState_Swap(myThreadState); // store previous current in save,
@@ -93,12 +95,12 @@ PyLockWrapper PyInterp_base::GetLockWrapper(){
 
 // main python interpreter
 
-PyThreadState *PyInterp_base::_gtstate = 0; // force 0 before execution
+// PyThreadState *PyInterp_base::_gtstate = 0; // force 0 before execution
 int PyInterp_base::_argc = 1;
 char* PyInterp_base::_argv[] = {""};
 
 PyObject *PyInterp_base::builtinmodule = NULL;
-PyObject *PyInterp_base::salome_shared_modules_module = NULL;
+//PyObject *PyInterp_base::salome_shared_modules_module = NULL;
 
 
 /*!
@@ -129,9 +131,9 @@ void PyInterp_base::initialize()
   _history.clear();       // start a new list of user's commands 
   _ith = _history.begin();
 
-  if(!_gtstate) init_python();
+  init_python();
   // Here the global lock is released
-  if(MYPYDEBUG) MESSAGE("PyInterp_base::initialize() - this = "<<this<<"; _gtstate = "<<_gtstate);
+  if(MYPYDEBUG) MESSAGE("PyInterp_base::initialize() - this = "<<this<<"; _gtstate = "<<KERNEL_PYTHON::_gtstate);
 
   // The lock will be acquired in initState. Make provision to release it on exit
   PyReleaseLock aReleaseLock;
@@ -165,23 +167,21 @@ void PyInterp_base::init_python()
    * The lock is released on init_python output
    * It is the caller responsability to acquire it if needed
    */
-  if(!_gtstate){
-    PyReleaseLock aReleaseLock;
-    Py_Initialize(); // Initialize the interpreter
-    PyEval_InitThreads(); // Initialize and acquire the global interpreter lock
-    PySys_SetArgv(_argc,_argv); // initialize sys.argv
-    _gtstate = PyThreadState_Get();
-    /*
-     * salome_shared_modules should be imported only once
-     */
-    salome_shared_modules_module = PyImport_ImportModule("salome_shared_modules");
-    if(!salome_shared_modules_module)
-      {
-       INFOS("PyInterp_base::initialize() - salome_shared_modules_module == NULL");
-       PyErr_Print();
-       PyErr_Clear();
-      }
-  }
+  MESSAGE("PyInterp_base::init_python");
+  ASSERT(KERNEL_PYTHON::_gtstate); // initialisation in main
+  SCRUTE(KERNEL_PYTHON::_gtstate);
+//   PyEval_RestoreThread(KERNEL_PYTHON::_gtstate);
+//   if(!salome_shared_modules_module) // import only once
+//     {
+//       salome_shared_modules_module=PyImport_ImportModule("salome_shared_modules");
+//     }
+//   if(!salome_shared_modules_module)
+//     {
+//       INFOS("salome_shared_modules_module == NULL");
+//       PyErr_Print();
+//       PyErr_Clear();
+//     }
+//   PyEval_ReleaseThread(KERNEL_PYTHON::_gtstate);
 }
 
 string PyInterp_base::getbanner()
index 739b5d4f0b09cf3f8aba9d26b3f065c82e4a633a..ac45028ec6445751beec7c00c0eb4ee2d16e2142 100644 (file)
@@ -64,11 +64,11 @@ ThreadLock GetPyThreadLock(const char* theComment = "");
 
 class PyInterp_base{
  public:
-  static PyThreadState *_gtstate;
+  //static PyThreadState *_gtstate;
   static int _argc;
   static char* _argv[];
   static PyObject *builtinmodule;
-  static PyObject *salome_shared_modules_module;
+  //static PyObject *salome_shared_modules_module;
   
   PyInterp_base();
   ~PyInterp_base();
index a2ea8ac56e0e547345bc80da2879c70dff61e967..d66b451b9ded3c66def01235a392e11994ef98ab 100644 (file)
@@ -27,6 +27,7 @@
 //  $Header$
 
 #include "QAD_PyInterp.h"
+#include "Container_init_python.hxx"
 #include "utilities.h"
 
 using namespace std;
@@ -127,7 +128,8 @@ void QAD_PyInterp::initContext()
   }else{
     // Call init_shared_modules to initialize the shared import mechanism for modules 
     //that must not be imported twice
-    PyObjWrapper m2(PyObject_CallMethod(m1,"init_shared_modules","O",salome_shared_modules_module));
+    PyObjWrapper m2(PyObject_CallMethod(m1,"init_shared_modules","O",
+                                       KERNEL_PYTHON::salome_shared_modules_module));
     if(!m2){
       MESSAGE("initContext: problem with init_shared_modules call");
       PyErr_Print();
index a1106986d74ded6e6e48d8e4d768f2afd384fa64..6748448d55f635c9e9a2fd12e9a05551dd26c0a2 100644 (file)
@@ -49,6 +49,7 @@
 #include "Utils_CorbaException.hxx"
 #include "SALOMEGUI_QtCatchCorbaException.hxx"
 #include "SALOME_Event.hxx"
+#include "Container_init_python.hxx"
 
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Session)
@@ -90,6 +91,8 @@ static int MYDEBUG = 0;
 static int MYDEBUG = 0;
 #endif
 
+PyObject *salome_shared_modules_module = NULL;
+
 void MessageOutput( QtMsgType type, const char *msg )
 {
   switch ( type ) {
@@ -113,6 +116,27 @@ int main(int argc, char **argv)
   CORBA::ORB_var &orb = init( orbArgc , argv ) ;
   SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
   qInstallMsgHandler( MessageOutput );
+
+  /*
+   * Python initialisation : only once
+   */
+  int _argc = 1;
+  char* _argv[] = {""};
+  KERNEL_PYTHON::init_python(_argc,_argv);
+  PyEval_RestoreThread(KERNEL_PYTHON::_gtstate);
+  if(!KERNEL_PYTHON::salome_shared_modules_module) // import only once
+    {
+      KERNEL_PYTHON::salome_shared_modules_module =
+       PyImport_ImportModule("salome_shared_modules");
+    }
+  if(!KERNEL_PYTHON::salome_shared_modules_module)
+    {
+      INFOS("salome_shared_modules_module == NULL");
+      PyErr_Print();
+      PyErr_Clear();
+    }
+  PyEval_ReleaseThread(KERNEL_PYTHON::_gtstate);
+
   try
     {
       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
index d0e0fe234f8dad00df7402aad169af7655649fd9..89137f358d7e9a17250e3f12d84e38a132785629 100644 (file)
@@ -60,13 +60,16 @@ static ostream& operator<<(ostream& os, const CORBA::Exception& e)
   return os;
 }
 
-Engines::TestComponent_ptr create_intance(Engines::Container_ptr iGenFact)
+Engines::TestComponent_ptr create_instance(Engines::Container_ptr iGenFact,
+                                          string componenttName)
 {
   bool isLib =
-    iGenFact->load_component_Library("SalomeTestComponent");
+    iGenFact->load_component_Library(componenttName.c_str());
+  //    iGenFact->load_component_Library("SalomeTestComponent");
   ASSERT(isLib);
   CORBA::Object_var obj =
-    iGenFact->create_component_instance("SalomeTestComponent",
+    //    iGenFact->create_component_instance("SalomeTestComponent",
+    iGenFact->create_component_instance(componenttName.c_str(),
                                        0);
   Engines::TestComponent_var anInstance = Engines::TestComponent::_narrow(obj);
   MESSAGE("create anInstance");
@@ -99,7 +102,7 @@ int main (int argc, char * argv[])
       MESSAGE("------------------------------- create instances ");
       for (int iter = 0; iter < nbInstances ; iter++)
        {
-         instances[iter] = create_intance(iGenFact);
+         instances[iter] = create_instance(iGenFact,"SalomeTestComponent");
        }
 
       MESSAGE("------------------------------ set env instances ");
@@ -149,16 +152,29 @@ int main (int argc, char * argv[])
        } 
       MESSAGE("------------------------------- PYTHON ");
       {
-       bool isLib =
-         iGenFact->load_component_Library("SALOME_TestComponentPy");
-       ASSERT(isLib);
-       CORBA::Object_var obj =
-         iGenFact->create_component_instance("SALOME_TestComponentPy",
-                                             0);
-       Engines::TestComponent_var anInstance =
-         Engines::TestComponent::_narrow(obj);
-       MESSAGE("create anInstance");
-       SCRUTE(anInstance->instanceName());
+//     bool isLib =
+//       iGenFact->load_component_Library("SALOME_TestComponentPy");
+//     ASSERT(isLib);
+//     CORBA::Object_var obj =
+//       iGenFact->create_component_instance("SALOME_TestComponentPy",
+//                                           0);
+//     Engines::TestComponent_var anInstance =
+//       Engines::TestComponent::_narrow(obj);
+//     MESSAGE("create anInstance");
+//     SCRUTE(anInstance->instanceName());
+      MESSAGE("------------------------------- create instances ");
+      for (int iter = 0; iter < nbInstances ; iter++)
+       {
+         instances[iter] = create_instance(iGenFact,"SALOME_TestComponentPy");
+       }
+
+      MESSAGE("---------------------------------- get instances ");
+      for (int iter = 0; iter < nbInstances ; iter++)
+       {
+         Engines::TestComponent_var anInstance = instances[iter];
+         SCRUTE(anInstance->instanceName());
+         MESSAGE("Coucou " << anInstance->Coucou(iter));
+       }
       }
    
       // Clean-up.