diff --git a/Lib/test/support.py b/Lib/test/support.py --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -575,10 +575,27 @@ def _is_ipv6_enabled(): IPV6_ENABLED = _is_ipv6_enabled() -# A constant likely larger than the underlying OS pipe buffer size. +# A constant likely larger than the underlying OS pipe buffer size, to +# make writes blocking. # Windows limit seems to be around 512B, and many Unix kernels have a 64K pipe -# buffer size or 16*PAGE_SIZE: take a few megs to be sure. This +# buffer size or 16*PAGE_SIZE: take a few megs to be sure. PIPE_MAX_SIZE = 3 * 1000 * 1000 +if sys.platform == 'linux': + # Under Linux 2.6.35 and higher, read the actual buffer size using + # F_GETPIPE_SZ (see issue #17835). + try: + import fcntl + except ImportError: + pass + else: + r, w = os.pipe() + try: + PIPE_MAX_SIZE = fcntl.fcntl(w, 1032) + 1 + except OSError: + pass + finally: + os.close(r) + os.close(w) # decorator for skipping tests on non-IEEE 754 platforms diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -3069,7 +3069,7 @@ class SignalsTest(unittest.TestCase): # The buffered IO layer must check for pending signal # handlers, which in this case will invoke alarm_interrupt(). self.assertRaises(ZeroDivisionError, - wio.write, item * (support.PIPE_MAX_SIZE // len(item))) + wio.write, item * (support.PIPE_MAX_SIZE // len(item) + 1)) t.join() # We got one byte, get another one and check that it isn't a # repeat of the first one. @@ -3168,7 +3168,7 @@ class SignalsTest(unittest.TestCase): select = support.import_module("select") # A quantity that exceeds the buffer size of an anonymous pipe's # write end. - N = 1024 * 1024 + N = support.PIPE_MAX_SIZE r, w = os.pipe() fdopen_kwargs["closefd"] = False # We need a separate thread to read from the pipe and allow the