#ifdef _DEBUG_
static int MYDEBUG = 0;
+static int MYPYDEBUG = 0;
#else
static int MYDEBUG = 0;
+static int MYPYDEBUG = 0;
#endif
myThreadState(theThreadState),
mySaveThreadState(PyInterp_base::_gtstate)
{
- //if(MYDEBUG) MESSAGE(" PyLockWrapper(...) - myThreadState = "<<myThreadState<<" - "<<myMutex.locked());
- //myMutex.lock();
- //PyEval_RestoreThread(myThreadState);
-
PyEval_AcquireLock();
mySaveThreadState = PyThreadState_Swap(myThreadState);
-
- //PyEval_SaveThread();
-
- //mySaveThreadState = PyThreadState_Swap(myThreadState);
- //PyEval_ReleaseLock();
}
PyLockWrapper::~PyLockWrapper(){
- //if(MYDEBUG) MESSAGE("~PyLockWrapper(...) - myThreadState = "<<myThreadState);
- //PyEval_SaveThread();
- //myMutex.unlock();
-
PyThreadState_Swap(mySaveThreadState);
PyEval_ReleaseLock();
-
- //PyEval_RestoreThread(myThreadState);
-
- //PyEval_AcquireLock();
- //PyThreadState_Swap(mySaveThreadState);
}
class PyReleaseLock{
public:
~PyReleaseLock(){
- //if(MYDEBUG) MESSAGE("~PyReleaseLock()");
- //PyEval_SaveThread();
-
+ if(MYPYDEBUG) MESSAGE("~PyReleaseLock()");
PyEval_ReleaseLock();
}
};
PyLockWrapper PyInterp_base::GetLockWrapper(){
- return PyLockWrapper(_tstate);
+ return _tstate;
}
*/
PyInterp_base::PyInterp_base(): _tstate(0), _vout(0), _verr(0), _g(0), _atFirst(true)
{
- //if(MYDEBUG) MESSAGE("PyInterp_base::PyInterp_base() - this = "<<this);
+ if(MYPYDEBUG) MESSAGE("PyInterp_base::PyInterp_base() - this = "<<this);
}
PyInterp_base::~PyInterp_base()
{
- if(MYDEBUG) MESSAGE("PyInterp_base::~PyInterp_base() - this = "<<this);
+ if(MYPYDEBUG) MESSAGE("PyInterp_base::~PyInterp_base() - this = "<<this);
PyLockWrapper aLock(_tstate);
- PyThreadState_Swap(_tstate);
- Py_EndInterpreter(_tstate);
+ //Py_EndInterpreter(_tstate);
}
PySys_SetArgv(_argc,_argv); // initialize sys.argv
_gtstate = PyThreadState_Get();
}
- //if(MYDEBUG) MESSAGE("PyInterp_base::initialize() - this = "<<this<<"; _gtstate = "<<_gtstate);
+ if(MYPYDEBUG) MESSAGE("PyInterp_base::initialize() - this = "<<this<<"; _gtstate = "<<_gtstate);
salome_shared_modules_module = PyImport_ImportModule("salome_shared_modules");
if(!salome_shared_modules_module){
- if(MYDEBUG) MESSAGE("init_python: problem with salome_shared_modules import");
+ INFOS("PyInterp_base::initialize() - salome_shared_modules_module == NULL");
PyErr_Print();
PyErr_Clear();
}
// used to interpret & compile commands
PyObjWrapper m(PyImport_ImportModule("codeop"));
if(!m){
- if(MYDEBUG) MESSAGE("Problem...");
+ INFOS("PyInterp_base::initialize() - PyImport_ImportModule('codeop') failed");
PyErr_Print();
ASSERT(0);
return;
PySys_SetObject("stdout",PySys_GetObject("__stdout__"));
PySys_SetObject("stderr",PySys_GetObject("__stderr__"));
- //if(MYDEBUG) MESSAGE("PyInterp_base::initRun() - this = "<<this<<"; _verr = "<<_verr<<"; _vout = "<<_vout);
+ if(MYPYDEBUG) MESSAGE("PyInterp_base::initRun() - this = "<<this<<"; _verr = "<<_verr<<"; _vout = "<<_vout);
return 0;
}
PyObjWrapper vout(PyObject_CallMethod(_vout,"reset",""));
int ier = compile_command(command,_g);
- //if(MYDEBUG) MESSAGE("simpleRun(...) - this = "<<this<<"; command = '"<<command<<"'; ier = "<<ier);
// Outputs are redirected on standards outputs (console)
PySys_SetObject("stdout",PySys_GetObject("__stdout__"));
ThreadLock aStudyLock(myStudyMutex,"TInitEditorThread::aStudyLock");
ThreadLock aPyLock = GetPyThreadLock("TInitEditorThread::aPyLock");
if(MYDEBUG) MESSAGE("TInitEditorThread::run() - myInterp = "<<myInterp<<"; myMutex = "<<myMutex);
+ myListener->myBanner = myInterp->getbanner().c_str();
QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::INITIALIZE));
QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::PYTHON_OK));
QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::UNSET_CURSOR));
anId = QAD_PyEditor::PYTHON_ERROR;
if(ret > 0)
anId = QAD_PyEditor::PYTHON_INCOMPLETE;
- myListener->viewport()->unsetCursor();
+ myListener->myError = myInterp->getverr().c_str();
+ myListener->myOutput = myInterp->getvout().c_str();
QThread::postEvent(myListener, new QCustomEvent(anId));
QThread::postEvent(myListener, new QCustomEvent(QAD_PyEditor::UNSET_CURSOR));
}
}
else if ( r == idMap[ IdClear ] ) {
clear();
- ThreadLock aPyLock = GetPyThreadLock();
- setText(myInterp->getbanner().c_str());
+ setText(myBanner);
setText(_currentPrompt);
}
else if ( r == idMap[ IdSelectAll ] ) {
case PYTHON_ERROR:
{
_buf.truncate(0);
- ThreadLock aPyLock = GetPyThreadLock();
- setText(myInterp->getvout().c_str());
- setText(myInterp->getverr().c_str());
+ setText(myOutput);
+ setText(myError);
_currentPrompt = ">>> ";
setText(_currentPrompt);
break;