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:
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]
#include <dlfcn.h>
#include <unistd.h>
#include <Python.h>
+#include "Container_init_python.hxx"
#include "utilities.h"
using namespace std;
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;
// 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);
}
}
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");
"s",componentName);
int ret= PyInt_AsLong(result);
SCRUTE(ret);
- PyEval_ReleaseThread(gtstate);
+ PyEval_ReleaseThread(KERNEL_PYTHON::_gtstate);
if (ret) // import possible: Python component
{
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");
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 ) ;
--- /dev/null
+// 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);
+}
+
--- /dev/null
+// 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
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 =
#endif
#include <Python.h>
+#include "Container_init_python.hxx"
using namespace std;
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.
#include <Launchers.hxx>
+#include "utilities.h"
+
+using namespace std;
static int Launchers_IsLoaded = 0;
static PyObject * Launchers_module = 0;
}
void Launchers_assertInitialized() {
+ MESSAGE("===========================================================");
+ MESSAGE("Launchers_assertInitialized");
+ MESSAGE("===========================================================");
PyThreadState *_save;
if( !Py_IsInitialized() ) {
+ MESSAGE("===========================================================");
+ MESSAGE("Py_Initialize()");
+ MESSAGE("===========================================================");
Py_Initialize();
PyEval_InitThreads();
PyEval_SaveThread();
// $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;
* 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);
#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>
#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;
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,
// 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;
/*!
_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;
* 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()
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();
// $Header$
#include "QAD_PyInterp.h"
+#include "Container_init_python.hxx"
#include "utilities.h"
using namespace std;
}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();
#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)
static int MYDEBUG = 0;
#endif
+PyObject *salome_shared_modules_module = NULL;
+
void MessageOutput( QtMsgType type, const char *msg )
{
switch ( type ) {
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");
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");
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 ");
}
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.