From: Victor Stinner Date: Tue, 15 Mar 2016 16:23:35 +0000 (+0100) Subject: faulthandler: Test Py_FatalError() with GIL released X-Git-Tag: v3.6.0a1~469^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=57003f81ead9ff38150c1e4821811c66c296d33c;p=thirdparty%2FPython%2Fcpython.git faulthandler: Test Py_FatalError() with GIL released Issue #26558. --- diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py index 0d86cb5da819..12969d518435 100644 --- a/Lib/test/test_faulthandler.py +++ b/Lib/test/test_faulthandler.py @@ -185,6 +185,14 @@ class FaultHandlerTests(unittest.TestCase): 2, 'xyz') + def test_fatal_error_without_gil(self): + self.check_fatal_error(""" + import faulthandler + faulthandler._fatal_error(b'xyz', True) + """, + 2, + 'xyz') + @unittest.skipIf(sys.platform.startswith('openbsd') and HAVE_THREADS, "Issue #12868: sigaltstack() doesn't work on " "OpenBSD if Python is compiled with pthread") diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 14384b5d1cf2..45c9fcb2af5e 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -935,10 +935,18 @@ static PyObject * faulthandler_fatal_error_py(PyObject *self, PyObject *args) { char *message; - if (!PyArg_ParseTuple(args, "y:fatal_error", &message)) + int release_gil = 0; + if (!PyArg_ParseTuple(args, "y|i:fatal_error", &message, &release_gil)) return NULL; faulthandler_suppress_crash_report(); - Py_FatalError(message); + if (release_gil) { + Py_BEGIN_ALLOW_THREADS + Py_FatalError(message); + Py_END_ALLOW_THREADS + } + else { + Py_FatalError(message); + } Py_RETURN_NONE; }