[Python-Dev] Issue #8863 adds a new PYTHONNOFAULTHANDLER environment variable

Victor Stinner victor.stinner at haypocalc.com
Mon Dec 20 15:24:22 CET 2010


Le lundi 20 décembre 2010 08:22:40, vous avez écrit :
> >> Looking at your function list, my other concern is that you are calling
> >> Python API without holding the GIL, IIUC. In particular, you are
> >> accessing _PyThreadState_Current, which may not point to the current
> >> thread if the current thread has released the GIL.
> > 
> > Ah? Where does _PyThreadState_Current point to if the GIL is not hold
> > when the fault handler is called?
> 
> The GIL is likely held by a different thread, then.
> _PyThreadState_Current will point to the state of this other thread.

I tested when the GIL released: the fault handler is unable to retrieve "the" 
thread state and so the backtrace is not printed. Which thread state should be 
retrieve? I don't know yet: maybe the last active thread state?

It doesn't look trivial to fix this issue because if there is no thread (only 
the main thread), release the GIL clears the thread state pointer (to it to 
NULL) without storing it somewhere else (whereas with multiple threads, the 
last active thread is stored in "gil_last_holder". I should ask Antoine (or 
someone one) how the new GIL works.

> Of this thread? I don't think so. gil_last_holder might also refer to
> a different thread.

Another variable might be created to store the (pointer to the) last active 
thread state.

> > I don't think that it will possible the acquire the GIL in
> > Py_FatalError() or in the fault handler.
> 
> I agree.

We all love deadlocks :-)

Victor


More information about the Python-Dev mailing list