Commit 2ae4dfd5 authored by Clinton Stimpson's avatar Clinton Stimpson

BUG: Fix timeouts with python tests on Windows.

parent d5c62dc4
......@@ -366,6 +366,7 @@ class pqPythonEventSource::pqInternal
{
public:
QString FileName;
PyGILState_STATE MainState;
};
pqPythonEventSource::pqPythonEventSource(QObject* p)
......@@ -380,11 +381,11 @@ pqPythonEventSource::pqPythonEventSource(QObject* p)
#ifdef SIGINT
signal(SIGINT, SIG_DFL);
#endif
// add QtTesting to python's inittab, so it is
// available to all interpreters
PyImport_AppendInittab(const_cast<char*>("QtTesting"), initQtTesting);
}
// add QtTesting to python's inittab, so it is
// available to all interpreters
PyImport_AppendInittab(const_cast<char*>("QtTesting"), initQtTesting);
}
pqPythonEventSource::~pqPythonEventSource()
......@@ -484,6 +485,13 @@ void pqPythonEventSource::threadGetChildren()
this->guiAcknowledge();
}
void pqPythonEventSource::start()
{
PyEval_InitThreads();
PyEval_ReleaseLock();
pqThreadedEventSource::start();
}
void pqPythonEventSource::run()
{
QFile file(this->Internal->FileName);
......@@ -493,23 +501,17 @@ void pqPythonEventSource::run()
return;
}
PyEval_InitThreads();
PyEval_ReleaseLock();
PyThreadState* curState = PyThreadState_Get();
PyThreadState* threadState = Py_NewInterpreter();
Instance = this;
PyThreadState_Swap(threadState);
PyGILState_STATE gstate = PyGILState_Ensure();
// finally run the script
QByteArray wholeFile = file.readAll();
int result = PyRun_SimpleString(wholeFile.data()) == 0 ? 0 : 1;
PyThreadState_Swap(threadState);
Py_EndInterpreter(threadState);
PyThreadState_Swap(curState);
PyGILState_Release(gstate);
PyEval_ReleaseLock();
this->done(result);
}
......
......@@ -55,6 +55,7 @@ public:
protected:
virtual void run();
virtual void start();
protected slots:
void threadGetProperty();
......
......@@ -146,12 +146,13 @@ bool pqThreadedEventSource::postNextEvent(const QString& object,
void pqThreadedEventSource::start()
{
this->Internal->ShouldStop = 0;
this->Internal->start();
this->Internal->start(QThread::LowestPriority);
}
void pqThreadedEventSource::stop()
{
this->Internal->ShouldStop = 1;
this->Internal->wait();
}
bool pqThreadedEventSource::waitForGUI()
......@@ -173,7 +174,7 @@ void pqThreadedEventSource::guiAcknowledge()
{
while(this->Internal->Waiting == 0)
{
pqInternal::ThreadHelper::msleep(10);
pqInternal::ThreadHelper::msleep(50);
}
this->Internal->Waiting = 0;
......
......@@ -68,7 +68,7 @@ public:
const QString& argument);
/** tell this source to stop */
void stop();
virtual void stop();
/** Wait for the GUI thread to acknowledge an event.
A previously locked mutex must be passed in.
......@@ -87,7 +87,7 @@ private slots:
protected:
// start the thread
void start();
virtual void start();
// called by the testing thread to signify it is done
// pass in zero for success, non-zero for failure
......
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