Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-41586: Add pipesize parameter to subprocess. Add F_GETPIPE_SZ and F_SETPIPE_SZ to fcntl.#21921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
17 commits Select commit Hold shift + click to select a range
1e51d96 Add F_SETPIPE_SZ and F_GETPIPE_SZ to fcntl module
rhpvorderman a218c39 Add pipesize parameter for Popen class
rhpvorderman 02b1d43 Add test for F_SETPIPE_SZ and F_GETPIPE_SZ
rhpvorderman af05503 Ensure cross-platform compatibility for pipesize in subprocess.Popen
rhpvorderman 493d6c3 Add linux test for pipesize in subprocess
rhpvorderman aad24c6 Enable subprocess pipesize test for all platforms
rhpvorderman acf9ae4 Do not set pipesizes for Popen on Windows, as this can not be tested …
rhpvorderman 6815aaa Add F_GETPIPE_SZ, F_SETPIPE_SZ and subprocess.Popen pipesize argument…
rhpvorderman 6bfd6a5 Add Ruben Vorderman to ACKS for work on the pipesize parameter in sub…
rhpvorderman cf97235 Add blurb for bpo 41586
rhpvorderman 389e4e9 Simplify test fore F_GETPIPE_SZ and F_SETPIPE_SZ so no file cleanup i…
rhpvorderman e601174 Test F_SETPIPE_SZ and F_GETPIPE_SZ on all supported platforms
rhpvorderman 24f061b Intentionally exclude fcntl from subprocess.__all__ test.
rhpvorderman 58925f3 Properly format the pipesize argument in the subprocess docs.
rhpvorderman 15b759e Determine default dynamically
rhpvorderman d4d0886 Add test for pipesize default
rhpvorderman c129ca8 Add a note to the documentation about only Linux supporting the pipes…
rhpvorderman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -190,6 +190,19 @@ def test_fcntl_f_getpath(self): | ||
| 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. | ||
gpshead marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -39,6 +39,11 @@ | ||
| except ImportError: | ||
| grp = None | ||
| try: | ||
| import fcntl | ||
| except: | ||
| fcntl = None | ||
| if support.PGO: | ||
| raise unittest.SkipTest("test is not helpful for PGO") | ||
| @@ -661,6 +666,46 @@ def test_stdin_devnull(self): | ||
| p.wait() | ||
| self.assertEqual(p.stdin, None) | ||
| def test_pipesizes(self): | ||
gpshead marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| # stdin redirection | ||
| pipesize = 16 * 1024 | ||
| p = subprocess.Popen([sys.executable, "-c", | ||
| 'import sys; sys.stdin.read(); sys.stdout.write("out"); sys.stderr.write("error!")'], | ||
| stdin=subprocess.PIPE, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| pipesize=pipesize) | ||
| # We only assert pipe size has changed on platforms that support it. | ||
| if sys.platform != "win32" and hasattr(fcntl, "F_GETPIPE_SZ"): | ||
| for fifo in [p.stdin, p.stdout, p.stderr]: | ||
| self.assertEqual(fcntl.fcntl(fifo.fileno(), fcntl.F_GETPIPE_SZ), pipesize) | ||
| # Windows pipe size can be acquired with the GetNamedPipeInfoFunction | ||
| # https://docs.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-getnamedpipeinfo | ||
| # However, this function is not yet in _winapi. | ||
| p.stdin.write(b"pear") | ||
| p.stdin.close() | ||
| p.wait() | ||
| def test_pipesize_default(self): | ||
| p = subprocess.Popen([sys.executable, "-c", | ||
| 'import sys; sys.stdin.read(); sys.stdout.write("out");' | ||
| ' sys.stderr.write("error!")'], | ||
| stdin=subprocess.PIPE, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| pipesize=-1) | ||
| # UNIX tests using fcntl | ||
| if sys.platform != "win32" and hasattr(fcntl, "F_GETPIPE_SZ"): | ||
| fp_r, fp_w = os.pipe() | ||
| default_pipesize = fcntl.fcntl(fp_w, fcntl.F_GETPIPE_SZ) | ||
| for fifo in [p.stdin, p.stdout, p.stderr]: | ||
| self.assertEqual( | ||
| fcntl.fcntl(fifo.fileno(), fcntl.F_GETPIPE_SZ), default_pipesize) | ||
| # On other platforms we cannot test the pipe size (yet). But above code | ||
| # using pipesize=-1 should not crash. | ||
| p.stdin.close() | ||
| p.wait() | ||
| def test_env(self): | ||
| newenv = os.environ.copy() | ||
| newenv["FRUIT"] = "orange" | ||
| @@ -3503,7 +3548,7 @@ def test_getoutput(self): | ||
| def test__all__(self): | ||
| """Ensure that __all__ is populated properly.""" | ||
| intentionally_excluded ={"list2cmdline", "Handle", "pwd", "grp"} | ||
| intentionally_excluded ={"list2cmdline", "Handle", "pwd", "grp", "fcntl"} | ||
| exported = set(subprocess.__all__) | ||
| possible_exports = set() | ||
| import types | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions 2 Misc/NEWS.d/next/Library/2020-08-19-08-32-13.bpo-41586.IYjmjK.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add F_SETPIPE_SZ and F_GETPIPE_SZ to fcntl module. Allow setting pipesize on | ||
| subprocess.Popen. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.