Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57003f8

Browse files
committed
faulthandler: Test Py_FatalError() with GIL released
Issue #26558.
1 parent 4ddee7f commit 57003f8

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

Lib/test/test_faulthandler.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ def test_fatal_error(self):
185185
2,
186186
'xyz')
187187

188+
def test_fatal_error_without_gil(self):
189+
self.check_fatal_error("""
190+
import faulthandler
191+
faulthandler._fatal_error(b'xyz', True)
192+
""",
193+
2,
194+
'xyz')
195+
188196
@unittest.skipIf(sys.platform.startswith('openbsd') and HAVE_THREADS,
189197
"Issue #12868: sigaltstack() doesn't work on "
190198
"OpenBSD if Python is compiled with pthread")

Modules/faulthandler.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -935,10 +935,18 @@ static PyObject *
935935
faulthandler_fatal_error_py(PyObject *self, PyObject *args)
936936
{
937937
char *message;
938-
if (!PyArg_ParseTuple(args, "y:fatal_error", &message))
938+
int release_gil = 0;
939+
if (!PyArg_ParseTuple(args, "y|i:fatal_error", &message, &release_gil))
939940
return NULL;
940941
faulthandler_suppress_crash_report();
941-
Py_FatalError(message);
942+
if (release_gil) {
943+
Py_BEGIN_ALLOW_THREADS
944+
Py_FatalError(message);
945+
Py_END_ALLOW_THREADS
946+
}
947+
else {
948+
Py_FatalError(message);
949+
}
942950
Py_RETURN_NONE;
943951
}
944952

0 commit comments

Comments
 (0)