From 1c98a1c42ebd82096b87ad267b07e5ca153914dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sun, 3 Feb 2019 14:00:40 +0100 Subject: [PATCH] Partially fix shutting down Python --- src/CutterApplication.cpp | 11 +++++--- src/common/PythonManager.cpp | 27 +++++++++---------- src/common/PythonManager.h | 2 ++ .../{pluginSample.py => plugin_sample.py} | 0 4 files changed, 23 insertions(+), 17 deletions(-) rename src/plugins/{pluginSample.py => plugin_sample.py} (100%) diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index 1023105e..3498d765 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -170,8 +170,13 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc CutterApplication::~CutterApplication() { + QList plugins = Core()->getCutterPlugins(); + for (CutterPlugin *plugin : plugins) { + delete plugin; + } + delete mainWindow; - delete Python(); + Python()->shutdown(); } bool CutterApplication::event(QEvent *e) @@ -220,8 +225,8 @@ void CutterApplication::loadPlugins() Python()->addPythonPath(pluginsDir.absolutePath().toLatin1().data()); - CutterPlugin *cutterPlugin = nullptr; foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { + CutterPlugin *cutterPlugin = nullptr; if (fileName.endsWith(".py")) { // Load python plugins QStringList l = fileName.split(".py"); @@ -241,7 +246,7 @@ void CutterApplication::loadPlugins() } } - qInfo() << "Loaded" << plugins.length() << "plugins."; + qInfo() << "Loaded" << plugins.length() << "plugin(s)."; Core()->setCutterPlugins(plugins); } diff --git a/src/common/PythonManager.cpp b/src/common/PythonManager.cpp index 0d1cbb59..6443bc7c 100644 --- a/src/common/PythonManager.cpp +++ b/src/common/PythonManager.cpp @@ -25,20 +25,6 @@ PythonManager::PythonManager() PythonManager::~PythonManager() { - QList plugins = Core()->getCutterPlugins(); - for (CutterPlugin *plugin : plugins) { - delete plugin; - } - - restoreThread(); - - emit willShutDown(); - - Py_Finalize(); - - if (pythonHome) { - PyMem_RawFree(pythonHome); - } } void PythonManager::initPythonHome() @@ -85,6 +71,19 @@ void PythonManager::initialize() saveThread(); } +void PythonManager::shutdown() +{ + emit willShutDown(); + + restoreThread(); + + Py_Finalize(); + + if (pythonHome) { + PyMem_RawFree(pythonHome); + } +} + void PythonManager::addPythonPath(char *path) { restoreThread(); diff --git a/src/common/PythonManager.h b/src/common/PythonManager.h index d2878526..30a81d25 100644 --- a/src/common/PythonManager.h +++ b/src/common/PythonManager.h @@ -21,6 +21,8 @@ public: void initPythonHome(); void initialize(); + void shutdown(); + void addPythonPath(char *path); diff --git a/src/plugins/pluginSample.py b/src/plugins/plugin_sample.py similarity index 100% rename from src/plugins/pluginSample.py rename to src/plugins/plugin_sample.py