Hmmm something is wrong here with the Python interpreter

Former-commit-id: bfa87ac83ae1518348e5fe1ed77f20475134e1b0
This commit is contained in:
Johan 2013-11-28 16:26:32 +01:00
parent c18920b59e
commit 45e4aff5f1
3 changed files with 9 additions and 10 deletions

View File

@ -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);

View File

@ -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);

View File

@ -5,6 +5,8 @@
#include <effectengine/EffectEngine.h>
#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<std::string> EffectEngine::getEffects() const