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

python -m cProfile -s fails with non informative message #67608

Closed
rkuska mannequin opened this issue Feb 9, 2015 · 11 comments
Closed

python -m cProfile -s fails with non informative message #67608

rkuska mannequin opened this issue Feb 9, 2015 · 11 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@rkuska
Copy link
Mannequin

rkuska mannequin commented Feb 9, 2015

BPO 23420
Nosy @vstinner, @berkerpeksag, @matrixise, @rkuska, @stratakis, @mlouielu, @miss-islington
PRs
  • bpo-23420: Verify the value of '-s' when execute the CLI of cProfile #9925
  • [3.7] bpo-23420: Verify the value of '-s' when execute the CLI of cProfile (GH-9925) #9926
  • [3.6] bpo-23420: Verify the value of '-s' when execute the CLI of cProfile (GH-9925) #9927
  • [2.7] bpo-23420: Verify the value of '-s' when execute the CLI of cProfile (GH-9925) #9928
  • Files
  • sort-choices.patch: Add choices for sort option of cProfile
  • sort-choices.patch: missing space before imported module
  • sort-choices.patch: convert to list
  • 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 2018-10-17.13:07:16.793>
    created_at = <Date 2015-02-09.12:05:42.440>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'python -m cProfile -s fails with non informative message'
    updated_at = <Date 2018-10-17.13:09:22.863>
    user = 'https://github.com/rkuska'

    bugs.python.org fields:

    activity = <Date 2018-10-17.13:09:22.863>
    actor = 'matrixise'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-10-17.13:07:16.793>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2015-02-09.12:05:42.440>
    creator = 'rkuska'
    dependencies = []
    files = ['38053', '38054', '38055']
    hgrepos = []
    issue_num = 23420
    keywords = ['patch']
    message_count = 11.0
    messages = ['235602', '265765', '265813', '292147', '327876', '327884', '327891', '327892', '327893', '327894', '327895']
    nosy_count = 8.0
    nosy_names = ['vstinner', 'berker.peksag', 'matrixise', 'sYnfo', 'rkuska', 'cstratak', 'louielu', 'miss-islington']
    pr_nums = ['9925', '9926', '9927', '9928']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23420'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    @rkuska
    Copy link
    Mannequin Author

    rkuska mannequin commented Feb 9, 2015

    Originaly reported here: https://bugzilla.redhat.com/show_bug.cgi?id=1160640

    I've forgotten to add the sort value to the -s option of cProfile which results in a traceback instead of user friendly error message. In the example below hello.py just prints a "Hello World":

    $ python -m cProfile -s hello.py
    Traceback (most recent call last):
      File "/usr/lib64/python2.6/runpy.py", line 122, in _run_module_as_main
        "__main__", fname, loader, pkg_name)
      File "/usr/lib64/python2.6/runpy.py", line 34, in _run_code
        exec code in run_globals
      File "/usr/lib64/python2.6/cProfile.py", line 190, in <module>
        main()
      File "/usr/lib64/python2.6/cProfile.py", line 185, in main
        parser.print_usage()
      File "/usr/lib64/python2.6/optparse.py", line 1597, in print_usage
        print >>file, self.get_usage()
      File "/usr/lib64/python2.6/optparse.py", line 1583, in get_usage
        self.expand_prog_name(self.usage))
      File "/usr/lib64/python2.6/optparse.py", line 1560, in expand_prog_name
        return s.replace("%prog", self.get_prog_name())
      File "/usr/lib64/python2.6/optparse.py", line 1555, in get_prog_name
        return os.path.basename(sys.argv[0])
    IndexError: list index out of range

    Tested with python2.7, python3.4 with the same result.

    Attached patch adds choices for sort option of cProfile.

    $ python -m cProfile -s sdds.py
    Usage: cProfile.py [-o output_file_path] [-s sort] scriptfile [arg] ...

    cProfile.py: error: option -s: invalid choice: 'sdds.py' (choose from 'cumulative', 'module', 'ncalls', 'pcalls', 'file', 'line', 'name', 'calls', 'stdname', 'nfl', 'filename', 'cumtime', 'time', 'tottime')

    @rkuska rkuska mannequin added extension-modules C modules in the Modules dir type-feature A feature request or enhancement labels Feb 9, 2015
    @berkerpeksag berkerpeksag added stdlib Python modules in the Lib dir and removed extension-modules C modules in the Modules dir labels Feb 14, 2015
    @stratakis
    Copy link
    Mannequin

    stratakis mannequin commented May 17, 2016

    Any info regarding that? Patch seems good and it actually works.

    @berkerpeksag
    Copy link
    Member

    Patch looks good to me, but we need a test case.

    @berkerpeksag berkerpeksag added type-bug An unexpected behavior, bug, or error and removed type-feature A feature request or enhancement labels May 18, 2016
    @mlouielu
    Copy link
    Mannequin

    mlouielu mannequin commented Apr 23, 2017

    If we can solve bpo-30118 for argument unittest, and apply bpo-18971 for optparse to argparse, this issue will then can be solve, too.

    @matrixise
    Copy link
    Member

    Hi,

    Just used the content of the patch and apply it on master,
    Add a unittest and the blurb entry.

    @vstinner
    Copy link
    Member

    New changeset fcd5e84 by Victor Stinner (Stéphane Wirtel) in branch 'master':
    bpo-23420: Verify the value of '-s' when execute the CLI of cProfile (GH-9925)
    fcd5e84

    @miss-islington
    Copy link
    Contributor

    New changeset 657e3f9 by Miss Islington (bot) (Stéphane Wirtel) in branch '3.7':
    [3.7] bpo-23420: Verify the value of '-s' when execute the CLI of cProfile (GH-9925) (GH-9926)
    657e3f9

    @vstinner
    Copy link
    Member

    New changeset 669fa8b by Victor Stinner (Stéphane Wirtel) in branch '3.6':
    [3.6] bpo-23420: Verify the value of '-s' when execute the CLI of cProfile (GH-9925) (GH-9927)
    669fa8b

    @miss-islington
    Copy link
    Contributor

    New changeset 6e57382 by Miss Islington (bot) (Stéphane Wirtel) in branch '2.7':
    [2.7] bpo-23420: Verify the value of '-s' when execute the CLI of cProfile (GH-9925) (GH-9928)
    6e57382

    @vstinner
    Copy link
    Member

    Thanks Robert Kuska for the bug report and the initial patch, thanks Stéphane Wirtel for the PR (with the NEWS entry and the new test ;-))

    @vstinner vstinner added 3.7 (EOL) end of life 3.8 only security fixes labels Oct 17, 2018
    @matrixise
    Copy link
    Member

    welcome

    @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 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants