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) ...@@ -430,6 +430,8 @@ pqPythonEventSource::pqPythonEventSource(QObject* p)
// add QtTesting to python's inittab, so it is // add QtTesting to python's inittab, so it is
// available to all interpreters // available to all interpreters
PyImport_AppendInittab(const_cast<char*>("QtTesting"), initQtTesting); PyImport_AppendInittab(const_cast<char*>("QtTesting"), initQtTesting);
PyEval_ReleaseLock();
} }
pqPythonEventSource::~pqPythonEventSource() pqPythonEventSource::~pqPythonEventSource()
...@@ -538,15 +540,21 @@ void pqPythonEventSource::run() ...@@ -538,15 +540,21 @@ void pqPythonEventSource::run()
return; return;
} }
PyEval_AcquireLock();
PyThreadState* curState = PyThreadState_Get();
PyThreadState* threadState = Py_NewInterpreter(); PyThreadState* threadState = Py_NewInterpreter();
Instance = this; Instance = this;
PyThreadState_Swap(threadState);
// finally run the script // finally run the script
QByteArray wholeFile = file.readAll(); QByteArray wholeFile = file.readAll();
int result = PyRun_SimpleString(wholeFile.data()) == 0 ? 0 : 1; int result = PyRun_SimpleString(wholeFile.data()) == 0 ? 0 : 1;
Py_EndInterpreter(threadState); Py_EndInterpreter(threadState);
PyThreadState_Swap(curState);
PyEval_ReleaseLock();
this->done(result); 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