Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f87afb0

Browse files
Issue #21619: Cleaned up test_broken_pipe_cleanup.
Patch by Martin Panter.
1 parent e3207fe commit f87afb0

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

Lib/test/test_subprocess.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,21 +2523,19 @@ def test_invalid_args(self):
25232523

25242524
def test_broken_pipe_cleanup(self):
25252525
"""Broken pipe error should not prevent wait() (Issue 21619)"""
2526-
args = [sys.executable, "-c",
2527-
"import sys;"
2528-
"sys.stdin.close();"
2529-
"sys.stdout.close();"] # Signals that input pipe is closed
2530-
proc = subprocess.Popen(args,
2526+
proc = subprocess.Popen([sys.executable, '-c', 'pass'],
25312527
stdin=subprocess.PIPE,
2532-
stdout=subprocess.PIPE,
25332528
bufsize=support.PIPE_MAX_SIZE*2)
2534-
proc.stdout.read() # Make sure subprocess has closed its input
2535-
proc.stdin.write(b"x" * support.PIPE_MAX_SIZE)
2529+
proc = proc.__enter__()
2530+
# Prepare to send enough data to overflow any OS pipe buffering and
2531+
# guarantee a broken pipe error. Data is held in BufferedWriter
2532+
# buffer until closed.
2533+
proc.stdin.write(b'x' * support.PIPE_MAX_SIZE)
25362534
self.assertIsNone(proc.returncode)
2535+
# EPIPE expected under POSIX; EINVAL under Windows
25372536
self.assertRaises(OSError, proc.__exit__, None, None, None)
2538-
self.assertEqual(0, proc.returncode)
2537+
self.assertEqual(proc.returncode, 0)
25392538
self.assertTrue(proc.stdin.closed)
2540-
self.assertTrue(proc.stdout.closed)
25412539

25422540

25432541
def test_main():

0 commit comments

Comments
 (0)