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

Skip to content

Commit 2d51721

Browse files
author
Charles-François Natali
committed
Issue #12196: Add PIPE_MAX_SIZE to test.support, constant larger than the
underlying OS pipe buffer size.
1 parent b30eed9 commit 2d51721

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

Lib/test/support.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"threading_cleanup", "reap_children", "cpython_only", "check_impl_detail",
4949
"get_attribute", "swap_item", "swap_attr", "requires_IEEE_754",
5050
"TestHandler", "Matcher", "can_symlink", "skip_unless_symlink",
51-
"import_fresh_module", "requires_zlib"
51+
"import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE"
5252
]
5353

5454
class Error(Exception):
@@ -409,6 +409,13 @@ def _is_ipv6_enabled():
409409

410410
IPV6_ENABLED = _is_ipv6_enabled()
411411

412+
413+
# A constant likely larger than the underlying OS pipe buffer size.
414+
# Windows limit seems to be around 512B, and most Unix kernels have a 64K pipe
415+
# buffer size: take 1M to be sure.
416+
PIPE_MAX_SIZE = 1024 * 1024
417+
418+
412419
# decorator for skipping tests on non-IEEE 754 platforms
413420
requires_IEEE_754 = unittest.skipUnless(
414421
float.__getformat__("double").startswith("IEEE"),

Lib/test/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,7 @@ def _read():
26832683
# The buffered IO layer must check for pending signal
26842684
# handlers, which in this case will invoke alarm_interrupt().
26852685
self.assertRaises(ZeroDivisionError,
2686-
wio.write, item * (1024 * 1024))
2686+
wio.write, item * (support.PIPE_MAX_SIZE // len(item)))
26872687
t.join()
26882688
# We got one byte, get another one and check that it isn't a
26892689
# repeat of the first one.

Lib/test/test_subprocess.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,24 +489,21 @@ def test_communicate_pipe_buf(self):
489489
# This test will probably deadlock rather than fail, if
490490
# communicate() does not work properly.
491491
x, y = os.pipe()
492-
if mswindows:
493-
pipe_buf = 512
494-
else:
495-
pipe_buf = os.fpathconf(x, "PC_PIPE_BUF")
496492
os.close(x)
497493
os.close(y)
498494
p = subprocess.Popen([sys.executable, "-c",
499495
'import sys,os;'
500496
'sys.stdout.write(sys.stdin.read(47));'
501-
'sys.stderr.write("xyz"*%d);'
502-
'sys.stdout.write(sys.stdin.read())' % pipe_buf],
497+
'sys.stderr.write("x" * %d);'
498+
'sys.stdout.write(sys.stdin.read())' %
499+
support.PIPE_MAX_SIZE],
503500
stdin=subprocess.PIPE,
504501
stdout=subprocess.PIPE,
505502
stderr=subprocess.PIPE)
506503
self.addCleanup(p.stdout.close)
507504
self.addCleanup(p.stderr.close)
508505
self.addCleanup(p.stdin.close)
509-
string_to_write = b"abc"*pipe_buf
506+
string_to_write = b"a" * support.PIPE_MAX_SIZE
510507
(stdout, stderr) = p.communicate(string_to_write)
511508
self.assertEqual(stdout, string_to_write)
512509

0 commit comments

Comments
 (0)