diff options
author | Zhiming Wang <i@zhimingwang.org> | 2021-01-20 16:56:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-20 09:56:21 +0100 |
commit | 3554fa4abecfb77ac5fcaa5ce8310eeca5683960 (patch) | |
tree | 152dc55103cd8c62b737be5d63b4615aba1431cc | |
parent | bpo-41995: Handle allocation failure in _tracemalloc and _zoneinfo (GH-22635) (diff) | |
download | cpython-3554fa4abecfb77ac5fcaa5ce8310eeca5683960.tar.gz cpython-3554fa4abecfb77ac5fcaa5ce8310eeca5683960.tar.bz2 cpython-3554fa4abecfb77ac5fcaa5ce8310eeca5683960.zip |
bpo-42005: profile and cProfile catch BrokenPipeError (GH-22643)
-rwxr-xr-x | Lib/cProfile.py | 7 | ||||
-rwxr-xr-x | Lib/profile.py | 7 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-10-11-13-48-03.bpo-42005.Jq6Az-.rst | 2 |
3 files changed, 14 insertions, 2 deletions
diff --git a/Lib/cProfile.py b/Lib/cProfile.py index 59b4699feb5..22a7d0aade8 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 5cb017ed830..d8599fb4eeb 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 00000000000..be4ed7f55ff --- /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`. |