diff --git a/src/PythonQtThreadSupport.cpp b/src/PythonQtThreadSupport.cpp index e5fef9d83..66355ba6a 100644 --- a/src/PythonQtThreadSupport.cpp +++ b/src/PythonQtThreadSupport.cpp @@ -47,7 +47,7 @@ bool PythonQtGILScope::_enableGILScope = false; PythonQtGILScope::PythonQtGILScope() : _ensured(false) { - if (_enableGILScope) { + if (_enableGILScope && Py_IsInitialized()) { _state = PyGILState_Ensure(); _ensured = true; } diff --git a/tests/PythonQtTestCleanup.cpp b/tests/PythonQtTestCleanup.cpp index 862931215..c8a2d738e 100644 --- a/tests/PythonQtTestCleanup.cpp +++ b/tests/PythonQtTestCleanup.cpp @@ -79,6 +79,11 @@ void PythonQtTestCleanup::testSignalReceiverCleanup() void PythonQtTestCleanup::testPyFinalizeThenPythonQtCleanup() { + QVERIFY(_helper->runScript("import PythonQt.QtCore\n" + "timer = PythonQt.QtCore.QTimer(obj)\n" + "timer.connect('destroyed()', obj.onDestroyed)\n" + "obj.setPassed()\n")); + if (Py_IsInitialized()) { Py_Finalize(); } diff --git a/tests/PythonQtTestMain.cpp b/tests/PythonQtTestMain.cpp index 1ae76e2a6..a1bcc4b41 100644 --- a/tests/PythonQtTestMain.cpp +++ b/tests/PythonQtTestMain.cpp @@ -49,16 +49,16 @@ int main(int argc, char* argv[]) { QApplication qapp(argc, argv); + PythonQt::setEnableThreadSupport(QProcessEnvironment::systemEnvironment().contains("PYTHONQT_ENABLE_THREAD_SUPPORT")); + if (QProcessEnvironment::systemEnvironment().contains("PYTHONQT_RUN_ONLY_MEMORY_TESTS")) { PythonQtMemoryTests test; - QTest::qExec(&test, argc, argv); - return 0; + return QTest::qExec(&test, argc, argv); } if (QProcessEnvironment::systemEnvironment().contains("PYTHONQT_RUN_ONLY_CLEANUP_TESTS")) { PythonQtTestCleanup cleanup; - QTest::qExec(&cleanup, argc, argv); - return 0; + return QTest::qExec(&cleanup, argc, argv); } PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);