Commit 6edbb816 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

BUG: Fixed BUG #4823. The issue arose because of multithreading. When testing

with python was enabled, we have an interpretor initialized in a separate
thread. This requires that we use correct locking mechaism for python to work
correctly. Fixed that.
parent 4f8bee17
......@@ -430,6 +430,8 @@ pqPythonEventSource::pqPythonEventSource(QObject* p)
// add QtTesting to python's inittab, so it is
// available to all interpreters
PyImport_AppendInittab(const_cast<char*>("QtTesting"), initQtTesting);
PyEval_ReleaseLock();
}
pqPythonEventSource::~pqPythonEventSource()
......@@ -538,15 +540,21 @@ void pqPythonEventSource::run()
return;
}
PyEval_AcquireLock();
PyThreadState* curState = PyThreadState_Get();
PyThreadState* threadState = Py_NewInterpreter();
Instance = this;
PyThreadState_Swap(threadState);
// finally run the script
QByteArray wholeFile = file.readAll();
int result = PyRun_SimpleString(wholeFile.data()) == 0 ? 0 : 1;
Py_EndInterpreter(threadState);
PyThreadState_Swap(curState);
PyEval_ReleaseLock();
this->done(result);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment