Skip to content

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

Closed

Description

@rkuska
mannequin
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']

    Activity

    1. rkuska commented on Feb 9, 2015

      rkuskamannequin
      MannequinAuthor

      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')

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      and removed on Feb 14, 2015
    3. stratakis commented on May 17, 2016

      stratakismannequin
      Mannequin

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

    4. berkerpeksag commented on May 18, 2016

      @berkerpeksag
      Member

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

    5. added
      type-bugAn unexpected behavior, bug, or error
      and removed
      type-featureA feature request or enhancement
      on May 18, 2016
    6. mlouielu commented on Apr 23, 2017

      mlouielumannequin
      Mannequin

      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.

    7. matrixise commented on Oct 17, 2018

      @matrixise
      Member

      Hi,

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

    8. vstinner commented on Oct 17, 2018

      @vstinner
      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

    9. miss-islington commented on Oct 17, 2018

      @miss-islington
      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

    10. vstinner commented on Oct 17, 2018

      @vstinner
      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

    11. miss-islington commented on Oct 17, 2018

      @miss-islington
      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

    12. vstinner commented on Oct 17, 2018

      @vstinner
      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 ;-))

    13. matrixise commented on Oct 17, 2018

      @matrixise
      Member

      welcome

    14. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of life3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions