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 zmwangx
Recipients zmwangx
Date 2020-10-11.05:45:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1602395117.19.0.101668557354.issue42005@roundup.psfhosted.org>
In-reply-to
Content
Since profile/cProfile CLI interface prints a sorted list of stats, using head to limit output to the most relevant entries should be a fairly natural thing to do. Unfortunately, BrokenPipeError isn't caught, causing quite a bit of pollution to the output:

$ python3 -m cProfile -m http.server -h | head
usage: http.server [-h] [--cgi] [--bind ADDRESS] [--directory DIRECTORY]
                   [port]

positional arguments:
  port                  Specify alternate port [default: 8000]

optional arguments:
  -h, --help            show this help message and exit
  --cgi                 Run as CGI Server
  --bind ADDRESS, -b ADDRESS
Traceback (most recent call last):
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/cProfile.py", line 180, in <module>
    main()
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/cProfile.py", line 173, in main
    runctx(code, globs, None, options.outfile, options.sort)
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/cProfile.py", line 19, in runctx
    return _pyprofile._Utils(Profile).runctx(statement, globals, locals,
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/profile.py", line 66, in runctx
    self._show(prof, filename, sort)
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/profile.py", line 72, in _show
    prof.print_stats(sort)
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/cProfile.py", line 42, in print_stats
    pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/pstats.py", line 431, in print_stats
    self.print_line(func)
  File "/Users/zmwang/.pyenv/versions/3.9.0/lib/python3.9/pstats.py", line 513, in print_line
    print(f8(tt/nc), end=' ', file=self.stream)
BrokenPipeError: [Errno 32] Broken pipe
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe

I think the exception should be caught in order to suppress this noise.
History
Date User Action Args
2020-10-11 05:45:17zmwangxsetrecipients: + zmwangx
2020-10-11 05:45:17zmwangxsetmessageid: <1602395117.19.0.101668557354.issue42005@roundup.psfhosted.org>
2020-10-11 05:45:17zmwangxlinkissue42005 messages
2020-10-11 05:45:16zmwangxcreate