Skip to content

Commit 8fa3e17

Browse files
authored
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.
1 parent 8fc5839 commit 8fa3e17

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Python/traceback.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -797,12 +797,15 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
797797
PyFrameObject *frame;
798798
unsigned int depth;
799799

800-
if (write_header)
800+
if (write_header) {
801801
PUTS(fd, "Stack (most recent call first):\n");
802+
}
802803

803804
frame = _PyThreadState_GetFrame(tstate);
804-
if (frame == NULL)
805+
if (frame == NULL) {
806+
PUTS(fd, "<no Python frame>\n");
805807
return;
808+
}
806809

807810
depth = 0;
808811
while (frame != NULL) {
@@ -870,9 +873,9 @@ _Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
870873
Python thread state of the current thread.
871874
872875
PyThreadState_Get() doesn't give the state of the thread that caused
873-
the fault if the thread released the GIL, and so this function
874-
cannot be used. Read the thread specific storage (TSS) instead: call
875-
PyGILState_GetThisThreadState(). */
876+
the fault if the thread released the GIL, and so
877+
_PyThreadState_GET() cannot be used. Read the thread specific
878+
storage (TSS) instead: call PyGILState_GetThisThreadState(). */
876879
current_tstate = PyGILState_GetThisThreadState();
877880
}
878881

0 commit comments

Comments
 (0)