Exception in callback => GPF?

F

Francois De Serres

Hiho,

When there's an unhandled exception in my
extension-module's-callback-into-Python-function-object, I get a GPF and
Python exits.
When the exception is being handled within the callback (hence in
Python), I get a very significant hiccup (1 to 5 seconds freeze).

Question: is there a specific way to deal with exceptions when they
happen inside such a callback? I searched the web with no avail. All
callbacks examples I've seen seem not to care about exceptions.

Maybe of importance: the callback is initiated within a native thread.
My C extension module is calling back into Python like this:

/* Python callback function object. */
static PyObject * my_callback = NULL;

/* C callback function passed to the implementation. */
static void external_callback(const MidiData * const data) {

if (my_callback && (my_callback != Py_None)) {

if (! data) {
PyErr_SetString(PyExc_IndexError, getLastErrorMessage());
} else {

PyObject * arglist = NULL;
PyObject * result = NULL;

PyGILState_STATE gil = PyGILState_Ensure();

arglist = Py_BuildValue("(i,i,s#)", data->deviceIndex,
data->timestamp, data->buffer, data->size);// 0, 0, "test", 4);//
result = PyEval_CallObject(my_callback, arglist);

Py_DECREF(arglist);
Py_DECREF(result);

PyGILState_Release(gil);
}

}
}

TIA,
Francois
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top