]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42005: profile and cProfile catch BrokenPipeError (GH-22643)
authorZhiming Wang <i@zhimingwang.org>
Wed, 20 Jan 2021 08:56:21 +0000 (16:56 +0800)
committerGitHub <noreply@github.com>
Wed, 20 Jan 2021 08:56:21 +0000 (09:56 +0100)
Lib/cProfile.py
Lib/profile.py
Misc/NEWS.d/next/Library/2020-10-11-13-48-03.bpo-42005.Jq6Az-.rst [new file with mode: 0644]

index 59b4699feb5062aef3fef5110be0acf8d7ae4e61..22a7d0aade855fd83e72d251cdf6ee4336e41765 100755 (executable)
@@ -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
index 5cb017ed8300993ad9767db967e105926e2f0159..d8599fb4eebd66f2e15020b7b0a637b5140dc5f8 100755 (executable)
@@ -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 (file)
index 0000000..be4ed7f
--- /dev/null
@@ -0,0 +1,2 @@
+Fix CLI of :mod:`cProfile` and :mod:`profile` to catch
+:exc:`BrokenPipeError`.