diff --git a/libnymea-core/integrations/pythonintegrationplugin.cpp b/libnymea-core/integrations/pythonintegrationplugin.cpp index 9ae6f5de..d4a2f33a 100644 --- a/libnymea-core/integrations/pythonintegrationplugin.cpp +++ b/libnymea-core/integrations/pythonintegrationplugin.cpp @@ -274,7 +274,7 @@ PythonIntegrationPlugin::PythonIntegrationPlugin(QObject *parent) : IntegrationP PythonIntegrationPlugin::~PythonIntegrationPlugin() { - PyGILState_Ensure(); + PyGILState_STATE s = PyGILState_Ensure(); while (!m_runningThreads.isEmpty()) { PyObject *loop = m_runningThreads.keys().first(); @@ -283,7 +283,7 @@ PythonIntegrationPlugin::~PythonIntegrationPlugin() } Py_XDECREF(s_plugins.take(this)); - Py_FinalizeEx(); + PyGILState_Release(s); } void PythonIntegrationPlugin::initPython() @@ -302,6 +302,13 @@ void PythonIntegrationPlugin::initPython() s_mainThread = PyEval_SaveThread(); } +void PythonIntegrationPlugin::deinitPython() +{ + PyEval_RestoreThread(s_mainThread); + + Py_FinalizeEx(); +} + bool PythonIntegrationPlugin::loadScript(const QString &scriptFile) { QFileInfo fi(scriptFile); diff --git a/libnymea-core/integrations/pythonintegrationplugin.h b/libnymea-core/integrations/pythonintegrationplugin.h index 9a0e5af4..e34835e9 100644 --- a/libnymea-core/integrations/pythonintegrationplugin.h +++ b/libnymea-core/integrations/pythonintegrationplugin.h @@ -22,6 +22,7 @@ public: ~PythonIntegrationPlugin(); static void initPython(); + static void deinitPython(); bool loadScript(const QString &scriptFile); diff --git a/libnymea-core/integrations/thingmanagerimplementation.cpp b/libnymea-core/integrations/thingmanagerimplementation.cpp index d1a8a8d3..e8e9e653 100644 --- a/libnymea-core/integrations/thingmanagerimplementation.cpp +++ b/libnymea-core/integrations/thingmanagerimplementation.cpp @@ -101,6 +101,7 @@ ThingManagerImplementation::ThingManagerImplementation(HardwareManager *hardware ThingManagerImplementation::~ThingManagerImplementation() { + delete m_translator; foreach (Thing *thing, m_configuredThings) { @@ -116,6 +117,8 @@ ThingManagerImplementation::~ThingManagerImplementation() qCDebug(dcThingManager()) << "Not deleting plugin" << plugin->pluginName(); } } + + PythonIntegrationPlugin::deinitPython(); } QStringList ThingManagerImplementation::pluginSearchDirs() @@ -1951,7 +1954,7 @@ void ThingManagerImplementation::loadThingStates(Thing *thing) ThingClass thingClass = m_supportedThings.value(thing->thingClassId()); foreach (const StateType &stateType, thingClass.stateTypes()) { if (stateType.cached()) { - QVariant value(stateType.defaultValue()); + QVariant value = stateType.defaultValue(); if (settings.contains(stateType.id().toString())) { value = settings.value(stateType.id().toString()); @@ -1963,6 +1966,7 @@ void ThingManagerImplementation::loadThingStates(Thing *thing) } value.convert(stateType.type()); thing->setStateValue(stateType.id(), value); + qWarning() << "**** loaded state" << stateType.name() << value; } else { thing->setStateValue(stateType.id(), stateType.defaultValue()); }