bpo-42005: Fix CLI of cProfile and profile to catch BrokenPipeError

This commit is contained in:
Zhiming Wang 2020-10-11 21:14:09 +08:00
parent dcc997cd28
commit fa36b03e9d
No known key found for this signature in database
GPG Key ID: 5B58F95EC95965D8
3 changed files with 14 additions and 2 deletions

View File

@ -175,7 +175,12 @@ def main():
'__package__': None,
'__cached__': None,
}
try:
runctx(code, globs, None, options.outfile, options.sort)
except BrokenPipeError as exc:
# Prevent "Exception ignored" during interpreter shutdown.
sys.stdout = None
sys.exit(exc.errno)
else:
parser.print_usage()
return parser

View File

@ -595,7 +595,12 @@ def main():
'__package__': None,
'__cached__': None,
}
try:
runctx(code, globs, None, options.outfile, options.sort)
except BrokenPipeError as exc:
# Prevent "Exception ignored" during interpreter shutdown.
sys.stdout = None
sys.exit(exc.errno)
else:
parser.print_usage()
return parser

View File

@ -0,0 +1,2 @@
Fix CLI of :mod:`cProfile` and :mod:`profile` to catch
:exc:`BrokenPipeError`.