[Numpy-discussion] [ANN] numpy 1.4.0 rc2

Pauli Virtanen pav@iki...
Tue Dec 22 17:09:32 CST 2009


ti, 2009-12-22 kello 15:28 -0700, Charles R Harris kirjoitti: [clip]
> But what about the GIL? That's what I'm curious about. Do we need to
> hold the GIL to check and clear and error? If so, there are other
> places where this will matter. I was under the impression that each
> thread had it's own error stack. But I don't know much about the GIL.

The issue seems to be that

Py_BEGIN_ALLOW_THREADS / NPY_BEGIN_ALLOW_THREADS

calls Python/ceval.c:PyEval_SaveThread(), which calls
Python/pystate.c:PyThreadState_Swap, which sets the current thread state
(Python/pystate.c:_PyThreadState_Current) to NULL.

I'm not 100% sure if this is the same thing as releasing GIL, GIL is
probably a subset of this.

But, the exception information lives in the thread state -> NULL pointer
dereference in PyErr_* -> BOOM. 
And yes,

        PyObject *
        PyErr_Occurred(void)
        {
                PyThreadState *tstate = PyThreadState_GET();
        
                return tstate->curexc_type;
        }

which probably means it shouldn't be called between ALLOW_THREADS. Needs
to be wrapped between NPY_ALLOW_C_API & NPY_DISABLE_C_API, which call
PyGILState_Ensure, which resurrects the thread state from some global
dictionary or something.

Pauli





More information about the NumPy-Discussion mailing list