* calls initialize method defined in base class, which calls virtual methods
* initstate & initcontext redefined here
*/
-PyInterp_PyQt::PyInterp_PyQt()
+PyInterp_PyQt::PyInterp_PyQt(): PyInterp_base()
{
initialize();
}
_history.clear(); // start a new list of user's commands
_ith = _history.begin();
- PyReleaseLock aReleaseLock;
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();
+ }
}
+ // Here the global lock is released
if(MYPYDEBUG) MESSAGE("PyInterp_base::initialize() - this = "<<this<<"; _gtstate = "<<_gtstate);
- 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();
- }
+ // The lock will be acquired in initState. Make provision to release it on exit
+ PyReleaseLock aReleaseLock;
- //PyLockWrapper aLock(_tstate);
initState();
initContext();
void SALOME_PYQT_GUI::initInterp(int StudyID)
{
- MESSAGE("initInterp");
+ MESSAGE("SALOME_PYQT_GUI::initInterp");
if(mapInterp.find(StudyID) != mapInterp.end()){
- MESSAGE ( " StudyID is found " << StudyID );
+ MESSAGE ( "SALOME_PYQT_GUI::initInterp StudyID is found " << StudyID );
interp = mapInterp[StudyID];
return;
}else{
- MESSAGE ( " StudyID is not found " << StudyID );
+ MESSAGE ( "SALOME_PYQT_GUI::initInterp StudyID is not found " << StudyID );
+ /*
+ * The creation of Python interpretor must be protected par a C++ Lock because of C threads
+ */
+ ThreadLock aPyLock = GetPyThreadLock("SALOME_PYQT_GUI::initInterp");
interp=new PyInterp_PyQt();
mapInterp[StudyID] = interp;
}
*/
//=============================================================================
SALOME_PYQT_GUI::SALOME_PYQT_GUI( const QString& theName, QObject* theParent ) :
- SALOMEGUI( theName, theParent )
+ SALOMEGUI( theName, theParent ),_module(0)
{
MESSAGE("SALOME_PYQT_GUI::SALOME_PYQT_GUI");
}
bool SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent )
{
- MESSAGE("SALOME_PYQT_GUI::ActiveStudyChanged");
int StudyID = parent->getActiveApp()->getActiveStudy()->getStudyId();
+ MESSAGE("SALOME_PYQT_GUI::ActiveStudyChanged"<<StudyID<<" - " <<this);
initInterp(StudyID);
PyLockWrapper aLock = interp->GetLockWrapper();