This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pr0gg3d
Recipients pr0gg3d
Date 2009-08-03.20:32:38
SpamBayes Score 1.9107068e-07
Marked as misclassified No
Message-id <1249331560.84.0.146355793731.issue6635@psf.upfronthosting.co.za>
In-reply-to
Content
$ python -m profile
Usage: profile.py [-o output_file_path] [-s sort] scriptfile [arg] ...

$ python -m profile -s calls
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 122, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 34, in _run_code
    exec code in run_globals
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/profile.py", line 619, in <module>
    main()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/profile.py", line 614, in main
    parser.print_usage()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/optparse.py", line 1584, in print_usage
    print >>file, self.get_usage()
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/optparse.py", line 1570, in get_usage
    self.expand_prog_name(self.usage))
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/optparse.py", line 1547, in expand_prog_name
    return s.replace("%prog", self.get_prog_name())
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/optparse.py", line 1542, in get_prog_name
    return os.path.basename(sys.argv[0])
IndexError: list index out of range


This is triggered by an early override of sys.argv when usage() is called (Lib/profile.py:603):

    if not sys.argv[1:]:
        parser.print_usage()
        sys.exit(2)

    (options, args) = parser.parse_args()
    sys.argv[:] = args

    if (len(sys.argv) > 0):
        sys.path.insert(0, os.path.dirname(sys.argv[0]))
        run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
    else:
        parser.print_usage()
    return parser




In the "else" branch it tries to print usage but sys.argv[] were already overwritten.

Attached is the proposed patch (tested with 2.5, 2.6, 3.1).
History
Date User Action Args
2009-08-03 20:32:41pr0gg3dsetrecipients: + pr0gg3d
2009-08-03 20:32:40pr0gg3dsetmessageid: <1249331560.84.0.146355793731.issue6635@psf.upfronthosting.co.za>
2009-08-03 20:32:39pr0gg3dlinkissue6635 messages
2009-08-03 20:32:38pr0gg3dcreate