Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracemalloc.Traceback.format() should have an option to reverse the traceback #76302

Closed
pitrou opened this issue Nov 23, 2017 · 9 comments
Closed
Labels
3.7 stdlib type-feature

Comments

@pitrou
Copy link
Member

@pitrou pitrou commented Nov 23, 2017

BPO 32121
Nosy @pitrou, @vstinner, @serhiy-storchaka, @Jesse-Bakker
PRs
  • #4534
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-11-29.23:05:52.607>
    created_at = <Date 2017-11-23.20:10:20.707>
    labels = ['3.7', 'type-feature', 'library']
    title = 'tracemalloc.Traceback.format() should have an option to reverse the traceback'
    updated_at = <Date 2017-11-29.23:05:52.606>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2017-11-29.23:05:52.606>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-11-29.23:05:52.607>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2017-11-23.20:10:20.707>
    creator = 'pitrou'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32121
    keywords = ['patch']
    message_count = 9.0
    messages = ['306856', '306859', '306863', '306885', '306886', '306892', '306897', '307272', '307273']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'vstinner', 'serhiy.storchaka', 'jbakker']
    pr_nums = ['4534']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue32121'
    versions = ['Python 3.7']

    @pitrou
    Copy link
    Member Author

    @pitrou pitrou commented Nov 23, 2017

    Right now tracemalloc.Traceback.format() returns the frames in "most recent call first" order. This is not intuitive since ordinary Python tracebacks are displayed in "most recent call last" order. It would be nice to add a reverse argument to change that.

    @pitrou pitrou added 3.7 stdlib type-feature labels Nov 23, 2017
    @vstinner
    Copy link
    Member

    @vstinner vstinner commented Nov 23, 2017

    The option seems reasonable. Would you like to work on a pull request?

    @Jesse-Bakker
    Copy link
    Mannequin

    @Jesse-Bakker Jesse-Bakker mannequin commented Nov 24, 2017

    I can work on this if you want. Can have a PR ready in a few minutes.

    @vstinner
    Copy link
    Member

    @vstinner vstinner commented Nov 24, 2017

    tracemalloc.Traceback contains "raw" data from the C _tracemalloc module. But since we are at Python level, we are free to change how data is rendered to user.

    Since Antoine Pitrou was surprised by the current frame order in Traceback.format() ("This is not intuitive since ordinary Python tracebacks are displayed in "most recent call last" order"), what do you think of adding a new parameter but also **reverse frames by default**?

    Maybe we can go further and even reverse frames in Traceback constructor? This is a backward incompatible change, but I don't think that a lot of code in the wild uses the tracemalloc *API*.

    About the parameter name: I'm ok with "reverse". *But* if we reverse by default, the "reverse" name can be confusing. Maybe we can use a less confusing name like "most_recent_last=True" (or "most_recent_first=False")?

    --

    Note: The faulthandler module also dumps starting with the "(most recent call first)", but I don't want to change that. It's for technical reason: faulthandler is called when something really bad happens and so Python internal structures may be corrupted. Moreover, frames is a single chained list, it's hard to iterate over them in the backward order (especially in faulthandler code where heap memory allocations are denied).

    @pitrou
    Copy link
    Member Author

    @pitrou pitrou commented Nov 24, 2017

    what do you think of adding a new parameter but also **reverse frames by default**?

    This would be fine with me. I didn't want to suggest it because it would break compatibility but obviously I find the current behaviour annoying :-)

    @serhiy-storchaka
    Copy link
    Member

    @serhiy-storchaka serhiy-storchaka commented Nov 24, 2017

    While we are here, what if make a negative limit truncating from the opposite side, as in the traceback module?

    @vstinner
    Copy link
    Member

    @vstinner vstinner commented Nov 24, 2017

    Serhiy:

    While we are here, what if make a negative limit truncating from the opposite side, as in the traceback module?

    Why not. I'm not opposed to that :-)

    @vstinner
    Copy link
    Member

    @vstinner vstinner commented Nov 29, 2017

    New changeset 706e10b by Victor Stinner (Jesse-Bakker) in branch 'master':
    bpo-32121: Add most_recent_first parameter to tracemalloc.Traceback.format (bpo-4534)
    706e10b

    @vstinner
    Copy link
    Member

    @vstinner vstinner commented Nov 29, 2017

    Jesse Bakker implemented all requested changes, I merged his PR. Well done, Jesse!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 stdlib type-feature
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants