From 45e4aff5f1551724dac89efaa85e55c4a52b4496 Mon Sep 17 00:00:00 2001 From: Johan Date: Thu, 28 Nov 2013 16:26:32 +0100 Subject: [PATCH] Hmmm something is wrong here with the Python interpreter Former-commit-id: bfa87ac83ae1518348e5fe1ed77f20475134e1b0 --- libsrc/effectengine/Effect.cpp | 12 ++++-------- libsrc/effectengine/Effect.h | 1 - libsrc/effectengine/EffectEngine.cpp | 6 +++++- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/libsrc/effectengine/Effect.cpp b/libsrc/effectengine/Effect.cpp index 791dd3b7..7d4184f0 100644 --- a/libsrc/effectengine/Effect.cpp +++ b/libsrc/effectengine/Effect.cpp @@ -12,7 +12,6 @@ PyMethodDef Effect::effectMethods[] = { {"setColor", Effect::wrapSetColor, METH_VARARGS, "Set a new color for the leds."}, {"setImage", Effect::wrapSetImage, METH_VARARGS, "Set a new image to process and determine new led colors."}, - {"getLedCount", Effect::wrapGetLedCount, METH_NOARGS, "Get the number of avaliable led channels."}, {"abort", Effect::wrapAbort, METH_NOARGS, "Check if the effect should abort execution."}, {NULL, NULL, 0, NULL} }; @@ -43,7 +42,10 @@ void Effect::run() // add methods extra builtin methods to the interpreter PyObject * thisCapsule = PyCapsule_New(this, nullptr, nullptr); - Py_InitModule4("hyperion", effectMethods, nullptr, thisCapsule, PYTHON_API_VERSION); + PyObject * module = Py_InitModule4("hyperion", effectMethods, nullptr, thisCapsule, PYTHON_API_VERSION); + + // add ledCount variable to the interpreter + PyObject_SetAttrString(module, "ledCount", Py_BuildValue("i", _imageProcessor->getLedCount())); // Set the end time if applicable if (_timeout > 0) @@ -89,12 +91,6 @@ PyObject* Effect::wrapSetImage(PyObject *self, PyObject *args) return Py_BuildValue("i", 42); } -PyObject* Effect::wrapGetLedCount(PyObject *self, PyObject *args) -{ - Effect * effect = getEffect(self); - return Py_BuildValue("i", effect->_imageProcessor->getLedCount()); -} - PyObject* Effect::wrapAbort(PyObject *self, PyObject *) { Effect * effect = getEffect(self); diff --git a/libsrc/effectengine/Effect.h b/libsrc/effectengine/Effect.h index 0f45b1f8..1199967e 100644 --- a/libsrc/effectengine/Effect.h +++ b/libsrc/effectengine/Effect.h @@ -35,7 +35,6 @@ private: static PyMethodDef effectMethods[]; static PyObject* wrapSetColor(PyObject *self, PyObject *args); static PyObject* wrapSetImage(PyObject *self, PyObject *args); - static PyObject* wrapGetLedCount(PyObject *self, PyObject *args); static PyObject* wrapAbort(PyObject *self, PyObject *args); static Effect * getEffect(PyObject *self); diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index 2771f3f8..c34891b0 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -5,6 +5,8 @@ #include #include "Effect.h" +//static PyThreadState *_mainThreadState = 0; + EffectEngine::EffectEngine(Hyperion * hyperion) : _hyperion(hyperion), _availableEffects(), @@ -21,6 +23,7 @@ EffectEngine::EffectEngine(Hyperion * hyperion) : std::cout << "Initializing Python interpreter" << std::endl; Py_InitializeEx(0); PyEval_InitThreads(); // Create the GIL + //_mainThreadState = PyEval_SaveThread(); PyEval_ReleaseLock(); // Release the GIL } @@ -29,7 +32,8 @@ EffectEngine::~EffectEngine() // clean up the Python interpreter std::cout << "Cleaning up Python interpreter" << std::endl; PyEval_AcquireLock(); // Get the Gil - Py_Finalize(); + //PyEval_RestoreThread(_mainThreadState); + //Py_Finalize(); } std::list EffectEngine::getEffects() const