summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xLib/cProfile.py7
-rwxr-xr-xLib/profile.py7
-rw-r--r--Misc/NEWS.d/next/Library/2020-10-11-13-48-03.bpo-42005.Jq6Az-.rst2
3 files changed, 14 insertions, 2 deletions
diff --git a/Lib/cProfile.py b/Lib/cProfile.py
index 59b4699..22a7d0a 100755
--- a/Lib/cProfile.py
+++ b/Lib/cProfile.py
@@ -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
diff --git a/Lib/profile.py b/Lib/profile.py
index 5cb017ed..d8599fb 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -595,7 +595,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/Misc/NEWS.d/next/Library/2020-10-11-13-48-03.bpo-42005.Jq6Az-.rst b/Misc/NEWS.d/next/Library/2020-10-11-13-48-03.bpo-42005.Jq6Az-.rst
new file mode 100644
index 0000000..be4ed7f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-10-11-13-48-03.bpo-42005.Jq6Az-.rst
@@ -0,0 +1,2 @@
+Fix CLI of :mod:`cProfile` and :mod:`profile` to catch
+:exc:`BrokenPipeError`.