From 5825661a4fd8d45363dfd9d6681a77f70b440a22 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Thu, 16 Apr 2020 00:53:29 +0100 Subject: [PATCH] Only initialise Python once When switching instances, the Python runner gets another initPython call, despite the previous interpreter existing. Most of the function was either a no-op or was redundant, and the GIL state got confusing. This is the simplest fix. If things catch fire that I haven't anticipated, instead of returning true, we can destroy the pre-existing interpreter and create a new one by running the rest of the function. --- src/runner/pythonrunner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 9cc65d1..113e26c 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -1347,6 +1347,8 @@ BOOST_PYTHON_MODULE(moprivate) bool PythonRunner::initPython(const QString &pythonPath) { + if (Py_IsInitialized()) + return true; try { if (!pythonPath.isEmpty() && !QFile::exists(pythonPath + "/python.exe")) { return false;