Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf64a58

Browse filesBrowse files
gh-128400: Only show the current thread in Py_FatalError on the free-threaded build (#128758)
1 parent 4533036 commit bf64a58
Copy full SHA for bf64a58

File tree

Expand file treeCollapse file tree

4 files changed

+22
-12
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+22
-12
lines changed

‎Lib/test/test_capi/test_misc.py

Copy file name to clipboardExpand all lines: Lib/test/test_capi/test_misc.py
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class InstanceMethod:
7575
id = _testcapi.instancemethod(id)
7676
testfunction = _testcapi.instancemethod(testfunction)
7777

78+
CURRENT_THREAD_REGEX = r'Current thread.*:\n' if not support.Py_GIL_DISABLED else r'Stack .*:\n'
79+
7880
class CAPITest(unittest.TestCase):
7981

8082
def test_instancemethod(self):
@@ -234,8 +236,8 @@ def test_return_null_without_error(self):
234236
r'Python runtime state: initialized\n'
235237
r'SystemError: <built-in function return_null_without_error> '
236238
r'returned NULL without setting an exception\n'
237-
r'\n'
238-
r'Current thread.*:\n'
239+
r'\n' +
240+
CURRENT_THREAD_REGEX +
239241
r' File .*", line 6 in <module>\n')
240242
else:
241243
with self.assertRaises(SystemError) as cm:
@@ -268,8 +270,8 @@ def test_return_result_with_error(self):
268270
r'SystemError: <built-in '
269271
r'function return_result_with_error> '
270272
r'returned a result with an exception set\n'
271-
r'\n'
272-
r'Current thread.*:\n'
273+
r'\n' +
274+
CURRENT_THREAD_REGEX +
273275
r' File .*, line 6 in <module>\n')
274276
else:
275277
with self.assertRaises(SystemError) as cm:
@@ -298,8 +300,8 @@ def test_getitem_with_error(self):
298300
r'with an exception set\n'
299301
r'Python runtime state: initialized\n'
300302
r'ValueError: bug\n'
301-
r'\n'
302-
r'Current thread .* \(most recent call first\):\n'
303+
r'\n' +
304+
CURRENT_THREAD_REGEX +
303305
r' File .*, line 6 in <module>\n'
304306
r'\n'
305307
r'Extension modules: _testcapi \(total: 1\)\n')

‎Lib/test/test_faulthandler.py

Copy file name to clipboardExpand all lines: Lib/test/test_faulthandler.py
+8-6Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ def check_error(self, code, lineno, fatal_error, *,
101101
Raise an error if the output doesn't match the expected format.
102102
"""
103103
all_threads_disabled = (
104-
(not py_fatal_error)
105-
and all_threads
104+
all_threads
106105
and (not sys._is_gil_enabled())
107106
)
108107
if all_threads and not all_threads_disabled:
@@ -116,12 +115,15 @@ def check_error(self, code, lineno, fatal_error, *,
116115
if py_fatal_error:
117116
regex.append("Python runtime state: initialized")
118117
regex.append('')
119-
if all_threads_disabled:
118+
if all_threads_disabled and not py_fatal_error:
120119
regex.append("<Cannot show all threads while the GIL is disabled>")
121120
regex.append(fr'{header} \(most recent call first\):')
122-
if garbage_collecting and not all_threads_disabled:
123-
regex.append(' Garbage-collecting')
124-
regex.append(fr' File "<string>", line {lineno} in {function}')
121+
if support.Py_GIL_DISABLED and py_fatal_error and not know_current_thread:
122+
regex.append(" <tstate is freed>")
123+
else:
124+
if garbage_collecting and not all_threads_disabled:
125+
regex.append(' Garbage-collecting')
126+
regex.append(fr' File "<string>", line {lineno} in {function}')
125127
regex = '\n'.join(regex)
126128

127129
if other_regex:
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:c:func:`Py_FatalError` no longer shows all threads on the :term:`free
2+
threaded <free threading>` build to prevent crashes.

‎Python/pylifecycle.c

Copy file name to clipboardExpand all lines: Python/pylifecycle.c
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,11 @@ _Py_FatalError_DumpTracebacks(int fd, PyInterpreterState *interp,
30343034
PUTS(fd, "\n");
30353035

30363036
/* display the current Python stack */
3037+
#ifndef Py_GIL_DISABLED
30373038
_Py_DumpTracebackThreads(fd, interp, tstate);
3039+
#else
3040+
_Py_DumpTraceback(fd, tstate);
3041+
#endif
30383042
}
30393043

30403044
/* Print the current exception (if an exception is set) with its traceback,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.