Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/json/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ def main():


if __name__ == '__main__':
main()
try:
main()
except BrokenPipeError as exc:
sys.exit(exc.errno)
11 changes: 11 additions & 0 deletions Lib/test/test_json/test_tool.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import errno
import os
import sys
import textwrap
import unittest

from subprocess import Popen, PIPE
from test import support
from test.support.script_helper import assert_python_ok
Expand Down Expand Up @@ -120,3 +122,12 @@ def test_sort_keys_flag(self):
self.assertEqual(out.splitlines(),
self.expect_without_sort_keys.encode().splitlines())
self.assertEqual(err, b'')

@unittest.skipIf(sys.platform =="win32", "The test is failed with ValueError on Windows")
def test_broken_pipe_error(self):
cmd = [sys.executable, '-m', 'json.tool']
proc = Popen(cmd, stdout=PIPE, stdin=PIPE)
# bpo-39828: Closing before json.tool attempts to write into stdout.
proc.stdout.close()
proc.communicate(b'"{}"')
self.assertEqual(proc.returncode, errno.EPIPE)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :mod:`json.tool` to catch :exc:`BrokenPipeError`. Patch by Dong-hee Na.