Skip to content

Commit 4491118

Browse files
Don't skip current tstate + update tests
1 parent 1d7eeb5 commit 4491118

5 files changed

Lines changed: 8 additions & 16 deletions

File tree

Include/internal/pycore_traceback.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,12 @@ extern void _Py_DumpTraceback(
5656
It is better to pass NULL to interp and current_tstate, the function tries
5757
different options to retrieve this information.
5858
59-
If skip_current_tstate is 1 then first tstate (current_tstate) will be skiped.
60-
This flag used in faulthandler_thread to skip self.
61-
6259
This function is signal safe. */
6360

6461
extern const char* _Py_DumpTracebackThreads(
6562
int fd,
6663
PyInterpreterState *interp,
67-
PyThreadState *current_tstate,
68-
int skip_current_tstate);
64+
PyThreadState *current_tstate);
6965

7066
/* Write a Unicode object into the file descriptor fd. Encode the string to
7167
ASCII using the backslashreplace error handler.

Lib/test/test_faulthandler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
THREAD_HEADER = fr'{THREAD_ID} \(most recent call first\):'
3232
CURRENT_THREAD_ID = fr'Current thread 0x[0-9a-f]+{THREAD_NAME}'
3333
CURRENT_THREAD_HEADER = fr'{CURRENT_THREAD_ID} \(most recent call first\):'
34+
THREAD_NO_PYTHON_FRAME = ' <no Python frame>'
3435

3536

3637
def expected_traceback(lineno1, lineno2, header, min_count=1):
@@ -676,6 +677,8 @@ def func(timeout, repeat, cancel, file, loops):
676677
if repeat:
677678
count *= 2
678679
header = (fr'Timeout \({timeout_str}\)!\n'
680+
fr'{CURRENT_THREAD_HEADER}\n'
681+
fr'{THREAD_NO_PYTHON_FRAME}\n\n'
679682
fr'{THREAD_HEADER}\n')
680683
regex = expected_traceback(17, 26, header, min_count=count)
681684
self.assertRegex(trace, regex)

Modules/faulthandler.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ faulthandler_dump_traceback(int fd, int all_threads,
205205
PyThreadState *tstate = PyGILState_GetThisThreadState();
206206

207207
if (all_threads == 1) {
208-
(void)_Py_DumpTracebackThreads(fd, NULL, tstate, 0);
208+
(void)_Py_DumpTracebackThreads(fd, NULL, tstate);
209209
}
210210
else {
211211
if (all_threads == FT_IGNORE_ALL_THREADS) {
@@ -273,7 +273,7 @@ faulthandler_dump_traceback_py_impl(PyObject *module, PyObject *file,
273273
/* gh-128400: Accessing other thread states while they're running
274274
* isn't safe if those threads are running. */
275275
_PyEval_StopTheWorld(interp);
276-
errmsg = _Py_DumpTracebackThreads(fd, NULL, tstate, 0);
276+
errmsg = _Py_DumpTracebackThreads(fd, NULL, tstate);
277277
_PyEval_StartTheWorld(interp);
278278
if (errmsg != NULL) {
279279
PyErr_SetString(PyExc_RuntimeError, errmsg);

Python/pylifecycle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3139,7 +3139,7 @@ _Py_FatalError_DumpTracebacks(int fd, PyInterpreterState *interp,
31393139

31403140
/* display the current Python stack */
31413141
#ifndef Py_GIL_DISABLED
3142-
_Py_DumpTracebackThreads(fd, interp, tstate, 0);
3142+
_Py_DumpTracebackThreads(fd, interp, tstate);
31433143
#else
31443144
_Py_DumpTraceback(fd, tstate);
31453145
#endif

Python/traceback.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,7 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current)
12391239
handlers if signals were received. */
12401240
const char*
12411241
_Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
1242-
PyThreadState *current_tstate,
1243-
int skip_current_tstate)
1242+
PyThreadState *current_tstate)
12441243
{
12451244
if (current_tstate == NULL) {
12461245
/* _Py_DumpTracebackThreads() is called from signal handlers by
@@ -1290,12 +1289,6 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
12901289
_Py_BEGIN_SUPPRESS_IPH
12911290
do
12921291
{
1293-
if (skip_current_tstate && current_tstate == tstate) {
1294-
tstate = PyThreadState_Next(tstate);
1295-
skip_current_tstate = 0;
1296-
continue;
1297-
}
1298-
12991292
if (nthreads != 0)
13001293
PUTS(fd, "\n");
13011294
if (nthreads >= MAX_NTHREADS) {

0 commit comments

Comments
 (0)