The GIL, callbacks, and GPFs

Thomas Heller theller at python.net
Wed Jul 6 20:59:05 CEST 2005


Francois De Serres <fdeserres at gmx.net> writes:

> Hello,
>
> I'm chasing a GPF in the interpreter when running my extension module.
> It's not very elaborated, but uses a system (threaded) callback, and
> therefore the GIL.
> Help would be mucho appreciated. Here's the rough picture:
>

> static void external_callback(const Bag * const bag) {       if
> (my_callback && (my_callback != Py_None)) {
>         PyObject * arglist = NULL;
>         PyObject * result = NULL;
>         arglist = Py_BuildValue("(s#)", bag->data, bag->size);
>           /* do it */
>         PyGILState_STATE gil = PyGILState_Ensure();

You're calling Py_BuildValue without holding the GIL.  Not sure if
that's the reason for your problems, but I don't think its ok.

>         result = PyEval_CallObject(my_callback, arglist);
>         PyGILState_Release(gil);
>                   Py_DECREF(arglist);
>         Py_DECREF(result);      }
> }

Thomas



More information about the Python-list mailing list