aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_fcntl.py
diff options
context:
space:
mode:
authorRuben Vorderman <r.h.p.vorderman@lumc.nl>2020-10-20 01:30:02 +0200
committerGitHub <noreply@github.com>2020-10-19 16:30:02 -0700
commit23c0fb8edd16fe6d796df2853a5369fd783e05b7 (patch)
treedb69e4ae0611f578233c1018a244c49ff9a51deb /Lib/test/test_fcntl.py
parentbf838227c35212709dc43b3c3c57f8e1655c1d24 (diff)
downloadcpython-23c0fb8edd16fe6d796df2853a5369fd783e05b7.tar.gz
cpython-23c0fb8edd16fe6d796df2853a5369fd783e05b7.zip
bpo-41586: Add pipesize parameter to subprocess & F_GETPIPE_SZ and F_SETPIPE_SZ to fcntl. (GH-21921)
* Add F_SETPIPE_SZ and F_GETPIPE_SZ to fcntl module * Add pipesize parameter for subprocess.Popen class This will allow the user to control the size of the pipes. On linux the default is 64K. When a pipe is full it blocks for writing. When a pipe is empty it blocks for reading. On processes that are very fast this can lead to a lot of wasted CPU cycles. On a typical Linux system the max pipe size is 1024K which is much better. For high performance-oriented libraries such as xopen it is nice to be able to set the pipe size. The workaround without this feature is to use my_popen_process.stdout.fileno() in conjuction with fcntl and 1031 (value of F_SETPIPE_SZ) to acquire this behavior.
Diffstat (limited to 'Lib/test/test_fcntl.py')
-rw-r--r--Lib/test/test_fcntl.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_fcntl.py b/Lib/test/test_fcntl.py
index 7e109208326..8d6e9ff7884 100644
--- a/Lib/test/test_fcntl.py
+++ b/Lib/test/test_fcntl.py
@@ -190,6 +190,19 @@ class TestFcntl(unittest.TestCase):
res = fcntl.fcntl(self.f.fileno(), fcntl.F_GETPATH, bytes(len(expected)))
self.assertEqual(expected, res)
+ @unittest.skipIf(not (hasattr(fcntl, "F_SETPIPE_SZ") and hasattr(fcntl, "F_GETPIPE_SZ")),
+ "F_SETPIPE_SZ and F_GETPIPE_SZ are not available on all unix platforms.")
+ def test_fcntl_f_pipesize(self):
+ test_pipe_r, test_pipe_w = os.pipe()
+ # Get the default pipesize with F_GETPIPE_SZ
+ pipesize_default = fcntl.fcntl(test_pipe_w, fcntl.F_GETPIPE_SZ)
+ # Multiply the default with 2 to get a new value.
+ fcntl.fcntl(test_pipe_w, fcntl.F_SETPIPE_SZ, pipesize_default * 2)
+ self.assertEqual(fcntl.fcntl(test_pipe_w, fcntl.F_GETPIPE_SZ), pipesize_default * 2)
+ os.close(test_pipe_r)
+ os.close(test_pipe_w)
+
+
def test_main():
run_unittest(TestFcntl)