summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-01-20 01:18:07 -0800
committerGitHub <noreply@github.com>2021-01-20 01:18:07 -0800
commit648b72900b5039ab46b8b459f921daecb8db2a6b (patch)
tree2601c07d8e05b5903d7689e06c138a2fb560c9bb /Lib
parentcloses bpo-42938: Replace snprintf with Python unicode formatting in ctypes p... (diff)
downloadcpython-648b72900b5039ab46b8b459f921daecb8db2a6b.tar.gz
cpython-648b72900b5039ab46b8b459f921daecb8db2a6b.tar.bz2
cpython-648b72900b5039ab46b8b459f921daecb8db2a6b.zip
bpo-42005: profile and cProfile catch BrokenPipeError (GH-22643)
(cherry picked from commit 3554fa4abecfb77ac5fcaa5ce8310eeca5683960) Co-authored-by: Zhiming Wang <i@zhimingwang.org>
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/cProfile.py7
-rwxr-xr-xLib/profile.py7
2 files changed, 12 insertions, 2 deletions
diff --git a/Lib/cProfile.py b/Lib/cProfile.py
index 47aacf9e2d4..406a9b7cf11 100755
--- a/Lib/cProfile.py
+++ b/Lib/cProfile.py
@@ -191,7 +191,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
diff --git a/Lib/profile.py b/Lib/profile.py
index 9df4435c5ae..df4450dac6a 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -611,7 +611,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