[3.8] bpo-38070: Py_FatalError() logs runtime state (GH-16258)
* bpo-38070: _Py_DumpTraceback() writes <no Python frame> (GH-16244)
When a Python thread has no frame, _Py_DumpTraceback() and
_Py_DumpTracebackThreads() now write "<no Python frame>", rather than
writing nothing.
(cherry picked from commit 8fa3e1740b3f03ea65ddb68411c2238c5f98eec2)
* bpo-38070: Enhance _PyObject_Dump() (GH-16243)
_PyObject_Dump() now dumps the object address for freed objects and
objects with ob_type=NULL.
(cherry picked from commit b39afb78768418d9405c4b528c80fa968ccc974d)
* bpo-38070: Add _PyRuntimeState.preinitializing (GH-16245)
Add _PyRuntimeState.preinitializing field: set to 1 while
Py_PreInitialize() is running.
_PyRuntimeState: rename also pre_initialized field to preinitialized.
(cherry picked from commit d3b904144e86e2442961de6a7dccecbe133d5c6d)
* bpo-38070: Py_FatalError() logs runtime state (GH-16246)
(cherry picked from commit 1ce16fb0977283ae42a9f8917bbca5f44aa69324)
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 4d6e2f2..ff7acac 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -198,6 +198,7 @@
self.assertRegex(err.replace(b'\r', b''),
br'Fatal Python error: a function returned NULL '
br'without setting an error\n'
+ br'Python runtime state: initialized\n'
br'SystemError: <built-in function '
br'return_null_without_error> returned NULL '
br'without setting an error\n'
@@ -225,6 +226,7 @@
self.assertRegex(err.replace(b'\r', b''),
br'Fatal Python error: a function returned a '
br'result with an error set\n'
+ br'Python runtime state: initialized\n'
br'ValueError\n'
br'\n'
br'The above exception was the direct cause '
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
index 1cf20db..d875103 100644
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -90,7 +90,8 @@
def check_error(self, code, line_number, fatal_error, *,
filename=None, all_threads=True, other_regex=None,
- fd=None, know_current_thread=True):
+ fd=None, know_current_thread=True,
+ py_fatal_error=False):
"""
Check that the fault handler for fatal errors is enabled and check the
traceback from the child process output.
@@ -110,10 +111,12 @@
{header} \(most recent call first\):
File "<string>", line {lineno} in <module>
"""
- regex = dedent(regex.format(
+ if py_fatal_error:
+ fatal_error += "\nPython runtime state: initialized"
+ regex = dedent(regex).format(
lineno=line_number,
fatal_error=fatal_error,
- header=header)).strip()
+ header=header).strip()
if other_regex:
regex += '|' + other_regex
output, exitcode = self.get_output(code, filename=filename, fd=fd)
@@ -170,7 +173,8 @@
""",
3,
'in new thread',
- know_current_thread=False)
+ know_current_thread=False,
+ py_fatal_error=True)
def test_sigabrt(self):
self.check_fatal_error("""
@@ -226,7 +230,8 @@
faulthandler._fatal_error(b'xyz')
""",
2,
- 'xyz')
+ 'xyz',
+ py_fatal_error=True)
def test_fatal_error_without_gil(self):
self.check_fatal_error("""
@@ -234,7 +239,8 @@
faulthandler._fatal_error(b'xyz', True)
""",
2,
- 'xyz')
+ 'xyz',
+ py_fatal_error=True)
@unittest.skipIf(sys.platform.startswith('openbsd'),
"Issue #12868: sigaltstack() doesn't work on "