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

Example for Profile Module shows incorrect method #62233

Closed
jough mannequin opened this issue May 22, 2013 · 8 comments
Closed

Example for Profile Module shows incorrect method #62233

jough mannequin opened this issue May 22, 2013 · 8 comments
Labels
docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@jough
Copy link
Mannequin

jough mannequin commented May 22, 2013

BPO 18033
Nosy @arigo, @orsenthil, @ezio-melotti, @phmc
Files
  • issue18033_py3.patch
  • issue18033_py2.patch
  • issue18033_py2.patch
  • 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 2013-09-08.00:53:55.230>
    created_at = <Date 2013-05-22.15:12:38.121>
    labels = ['easy', 'type-feature', 'docs']
    title = 'Example for Profile Module shows incorrect method'
    updated_at = <Date 2013-09-08.00:53:55.229>
    user = 'https://bugs.python.org/jough'

    bugs.python.org fields:

    activity = <Date 2013-09-08.00:53:55.229>
    actor = 'orsenthil'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2013-09-08.00:53:55.230>
    closer = 'orsenthil'
    components = ['Documentation']
    creation = <Date 2013-05-22.15:12:38.121>
    creator = 'jough'
    dependencies = []
    files = ['30390', '30391', '30760']
    hgrepos = []
    issue_num = 18033
    keywords = ['patch', 'easy']
    message_count = 8.0
    messages = ['189823', '190153', '190154', '190823', '190954', '192246', '197208', '197209']
    nosy_count = 9.0
    nosy_names = ['arigo', 'orsenthil', 'ezio.melotti', 'docs@python', 'python-dev', 'pconnell', 'dmi.baranov', 'jough', 'ohe']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18033'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @jough
    Copy link
    Mannequin Author

    jough mannequin commented May 22, 2013

    The example on this page:
    http://docs.python.org/2/library/profile.html?highlight=pstats#profile.Profile

    Shows:

    import cProfile, pstats, io
    pr = cProfile.Profile()
    pr.enable()
    ... do something ...
    pr.disable()
    s = io.StringIO()
    ps = pstats.Stats(pr, stream=s)
    ps.print_results()

    Where "ps.print_results()" should be "ps.print_stats()"

    @jough jough mannequin assigned docspython May 22, 2013
    @jough jough mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels May 22, 2013
    @dmibaranov
    Copy link
    Mannequin

    dmibaranov mannequin commented May 27, 2013

    Added py3 patch

    @dmibaranov
    Copy link
    Mannequin

    dmibaranov mannequin commented May 27, 2013

    py2

    @ezio-melotti
    Copy link
    Member

    Thanks for the patches, however the Python 2 example doesn't work.
    I think a BytesIO should be used instead of a StringIO, and print_stats() only returns a pstats.Stats instance, without actually printing any result.
    I wonder if print_results was an old method that has been removed and if now there's another way to print the results.
    I haven't tried on Python 3 yet, but the same comment might apply there too.

    @arigo
    Copy link
    Mannequin

    arigo mannequin commented Jun 11, 2013

    A slightly more complete example that I tested:

    http://stackoverflow.com/a/16077568/1556290

    @ohe
    Copy link
    Mannequin

    ohe mannequin commented Jul 3, 2013

    Here is a fixed version for python2.7. Using StringIO instead of io module fixes the problem pointed by Ezio.
    The print_stats method dumps the stats either on sys.stdout if Stats class is declared without a stream specification or in the given stream parameter (the name print_stats may be a bit misleading).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 8, 2013

    New changeset 93018d47793f by Senthil Kumaran in branch '2.7':
    Correct Profile class usage example. Addresses issue bpo-18033 .
    http://hg.python.org/cpython/rev/93018d47793f

    New changeset ab4d3ccb92e6 by Senthil Kumaran in branch '3.3':
    Correct Profile class usage example. Addresses issue bpo-18033.
    http://hg.python.org/cpython/rev/ab4d3ccb92e6

    New changeset 88182b388bae by Senthil Kumaran in branch 'default':
    merge from 3.3
    http://hg.python.org/cpython/rev/88182b388bae

    @orsenthil
    Copy link
    Member

    I consolidated the patches and example and have committed them to 2.7, 3.3 and 3.4. Thanks for your contributions.

    @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
    docs Documentation in the Doc dir easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants