470,631 Members | 1,621 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,631 developers. It's quick & easy.

Exception in callback => GPF?

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

Jul 21 '05 #1
0 956

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Homa | last post: by
1 post views Thread by Barry Anderberg | last post: by
4 posts views Thread by Bhavya Shah | last post: by
2 posts views Thread by koredump | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.