[Python-Dev] Issue #8863 adds a new PYTHONNOFAULTHANDLER environment variable (original) (raw)

Victor Stinner victor.stinner at haypocalc.com
Mon Dec 20 05:53:49 CET 2010


Le lundi 20 décembre 2010 à 02:05 +0100, "Martin v. Löwis" a écrit :

The problem is that merely being POSIX compliant would not be enough to allow calling a function in a signal handler. Instead, the function also needs to be async-signal safe.

Yes, this issue was fixed in an older version of my patch. Starting at version 9, the signal handler only call signal-safe functions.

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 PyThreadStateCurrent, 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? My patch changes also Py_FatalError() to display the Python backtrace.

It looks that _PyThreadState_Current can be NULL if the GIL is released. In this case, _Py_DumpBacktrace() just do nothing. There is also a gil_last_holder variable: can it be used to get the thread state (especially if the thread state was deleted)?

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

Victor



More information about the Python-Dev mailing list