You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
python -m cProfile -s fails with non informative message #67608
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_codeexec 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_usageprint>>file, self.get_usage()
File "/usr/lib64/python2.6/optparse.py", line 1583, in get_usageself.expand_prog_name(self.usage))
File "/usr/lib64/python2.6/optparse.py", line 1560, in expand_prog_namereturn s.replace("%prog", self.get_prog_name())
File "/usr/lib64/python2.6/optparse.py", line 1555, in get_prog_namereturn 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.
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
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
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
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
Activity
rkuska commentedon 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":
Tested with python2.7, python3.4 with the same result.
Attached patch adds
choicesfor sort option of cProfile.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')
stratakis commentedon May 17, 2016
Any info regarding that? Patch seems good and it actually works.
berkerpeksag commentedon May 18, 2016
Patch looks good to me, but we need a test case.
mlouielu commentedon 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 commentedon Oct 17, 2018
Hi,
Just used the content of the patch and apply it on master,
Add a unittest and the blurb entry.
vstinner commentedon Oct 17, 2018
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 commentedon Oct 17, 2018
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 commentedon Oct 17, 2018
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 commentedon Oct 17, 2018
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 commentedon Oct 17, 2018
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 ;-))
matrixise commentedon Oct 17, 2018
welcome