bpo-42005: profile and cProfile catch BrokenPipeError (GH-22643)

(cherry picked from commit 3554fa4abe)

Co-authored-by: Zhiming Wang <i@zhimingwang.org>
This commit is contained in:
Miss Islington (bot) 2021-01-20 01:19:08 -08:00 committed by GitHub
parent 50938b63fb
commit 0654c4c4cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 2 deletions

View file

@ -175,7 +175,12 @@ def main():
'__package__': None,
'__cached__': None,
}
runctx(code, globs, None, options.outfile, options.sort)
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