diff options
author | Jesse-Bakker <jessebakker00@gmail.com> | 2017-11-29 23:05:07 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-11-29 23:05:07 (GMT) |
commit | 706e10b186992e086e661a62d2c8ec9588525b31 (patch) | |
tree | 6ef28e2e18a1183757d3a31236c2b5e8b4434254 /Doc/library | |
parent | 859f7ce7a49f8bd6309748c05e460c10f6a433ed (diff) | |
download | cpython-706e10b186992e086e661a62d2c8ec9588525b31.zip cpython-706e10b186992e086e661a62d2c8ec9588525b31.tar.gz cpython-706e10b186992e086e661a62d2c8ec9588525b31.tar.bz2 |
bpo-32121: Add most_recent_first parameter to tracemalloc.Traceback.format (#4534)
* Add most_recent_first parameter to tracemalloc.Traceback.format to allow
reversing the order of the frames in the output
* Reversed default sorting of tracemalloc.Traceback frames
* Allowed negative limit, truncating from the other side.
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/tracemalloc.rst | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Doc/library/tracemalloc.rst b/Doc/library/tracemalloc.rst index 048ee64..2d327c0 100644 --- a/Doc/library/tracemalloc.rst +++ b/Doc/library/tracemalloc.rst @@ -650,8 +650,8 @@ Traceback .. class:: Traceback - Sequence of :class:`Frame` instances sorted from the most recent frame to - the oldest frame. + Sequence of :class:`Frame` instances sorted from the oldest frame to the + most recent frame. A traceback contains at least ``1`` frame. If the ``tracemalloc`` module failed to get a frame, the filename ``"<unknown>"`` at line number ``0`` is @@ -663,11 +663,17 @@ Traceback The :attr:`Trace.traceback` attribute is an instance of :class:`Traceback` instance. - .. method:: format(limit=None) + .. versionchanged:: 3.7 + Frames are now sorted from the oldest to the most recent, instead of most recent to oldest. - Format the traceback as a list of lines with newlines. Use the - :mod:`linecache` module to retrieve lines from the source code. If - *limit* is set, only format the *limit* most recent frames. + .. method:: format(limit=None, most_recent_first=False) + + Format the traceback as a list of lines with newlines. Use the + :mod:`linecache` module to retrieve lines from the source code. + If *limit* is set, format the *limit* most recent frames if *limit* + is positive. Otherwise, format the ``abs(limit)`` oldest frames. + If *most_recent_first* is ``True``, the order of the formatted frames + is reversed, returning the most recent frame first instead of last. Similar to the :func:`traceback.format_tb` function, except that :meth:`.format` does not include newlines. |