This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Warn unsuspecting readers that thread stacks are in reverse order
Type: enhancement Stage: resolved
Components: Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vstinner Nosy List: gvanrossum, pitrou, python-dev, vstinner
Priority: low Keywords: easy, patch

Created on 2013-10-20 00:23 by gvanrossum, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
traceback.diff gvanrossum, 2013-10-20 03:26 review
traceback2.diff gvanrossum, 2013-10-20 23:41 review
Messages (8)
msg200527 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2013-10-20 00:23
I was confused for a while when seeing the thread stacks dumped by the faulthandler module.  (See issue 19293.)

I propose the following tweaks of the output to make this more obvious. The first chunk changes the header written when called as _Py_DumpTraceback(), the second change the per-thread headers printed by _Py_DumpTracebackThreads().

diff -r 02f6922e6a7e Python/traceback.c
--- a/Python/traceback.c        Sat Oct 19 17:04:25 2013 -0700
+++ b/Python/traceback.c        Sat Oct 19 17:19:29 2013 -0700
@@ -603,7 +603,7 @@
     unsigned int depth;

     if (write_header)
-        PUTS(fd, "Traceback (most recent call first):\n");
+        PUTS(fd, "Stack (most recent call first):\n");

     frame = _PyThreadState_GetFrame(tstate);
     if (frame == NULL)
@@ -642,7 +642,7 @@
     else
         PUTS(fd, "Thread 0x");
     dump_hexadecimal(sizeof(long)*2, (unsigned long)tstate->thread_id, fd);
-    PUTS(fd, ":\n");
+    PUTS(fd, " (most recent call first):\n");
 }

 const char*
msg200537 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2013-10-20 03:26
BTW, another oddity in traceback.c: dump_hexadecimal() has the "int fd" argument at the end, while all other dump_*() functions have it at the front -- even its cousin dump_decimal(). Here's a patch that includes a fix.
msg200550 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-10-20 07:41
You must update unit tests in test_faulthandler.
msg200655 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2013-10-20 23:41
New patch, with fixed test.

TBH now I'm getting worried that other programs may exist that parse this format and will get confused.
msg200660 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-10-21 00:03
> TBH now I'm getting worried that other programs may exist that parse this format and will get confused.

A program parsing faulthandler output? Seriously? It would be nice, but I don't know any.

Anyway, such program would probably use a regex to parse the output, and it's very easy to support Python 3.3 format and patched (future 3.4) format.

> New patch, with fixed test.

Thanks. The patch looks good to me, you can push it.
msg200678 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-10-21 01:21
New changeset cc8c37b5b449 by Guido van Rossum in branch 'default':
Issue 19306: Add extra hints to faulthandler stack dumps that they are upside down.
http://hg.python.org/cpython/rev/cc8c37b5b449
msg200685 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2013-10-21 02:18
On Victor's authority, committed. I've also (separately) committed some doc changes.
msg200712 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-10-21 08:00
Thanks. "(most recent call first)" was already present in some cases, but I forgot to mention it in all cases.
History
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63505
2013-10-21 08:00:25vstinnersetmessages: + msg200712
2013-10-21 02:18:37gvanrossumsetstatus: open -> closed
resolution: fixed
messages: + msg200685

stage: patch review -> resolved
2013-10-21 01:21:11python-devsetnosy: + python-dev
messages: + msg200678
2013-10-21 00:03:38vstinnersetmessages: + msg200660
2013-10-20 23:41:44gvanrossumsetfiles: + traceback2.diff

messages: + msg200655
2013-10-20 07:41:23vstinnersetmessages: + msg200550
2013-10-20 03:26:56gvanrossumsetfiles: + traceback.diff
keywords: + patch
messages: + msg200537
2013-10-20 00:28:56pitrousetassignee: pitrou -> vstinner

nosy: + vstinner
2013-10-20 00:23:25gvanrossumcreate