-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
GH-134453: Fix subprocess memoryview input handling on POSIX #134949
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
base: main
Are you sure you want to change the base?
Conversation
Fix inconsistent subprocess.Popen.communicate() behavior between Windows and POSIX when using memoryview objects with non-byte elements as input. On POSIX systems, the code was incorrectly comparing bytes written against element count instead of byte count, causing data truncation for large inputs with non-byte element types. Changes: - Cast memoryview inputs to byte view when input is already a memoryview - Fix progress tracking to use len(input_view) instead of len(self._input) - Add comprehensive test coverage for memoryview inputs 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> pre-commit-whitespace-fixup
e1e8e52
to
6cd5c60
Compare
6cd5c60
to
7e1e75c
Compare
self.addCleanup(p.stdin.close) | ||
(stdout, stderr) = p.communicate(mv) | ||
self.assertEqual(stdout, test_data) | ||
self.assertEqual(stderr, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use assertIsNone
self.assertEqual(stderr, None) | |
self.assertIsNone(stderr, None) |
self.addCleanup(p.stdin.close) | ||
(stdout, stderr) = p.communicate(mv) | ||
self.assertEqual(stdout, expected_bytes) | ||
self.assertEqual(stderr, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.assertEqual(stderr, None) | |
self.assertIsNone(stderr, None) |
num_elements = (pipe_buf // 4) + 100 | ||
test_array = array.array('i', range(num_elements)) # 'i' = signed int (4 bytes each) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this test passes on the main branch. I think we want something like this:
num_elements = (pipe_buf // 4) + 100 | |
test_array = array.array('i', range(num_elements)) # 'i' = signed int (4 bytes each) | |
num_elements = pipe_buf + 1 | |
test_array = array.array('i', [1 for _ in range(num_elements)]) |
From what I can tell, the pipe is taking each integer as a single byte.
Fix inconsistent subprocess.Popen.communicate() behavior between Windows and POSIX when using memoryview objects with non-byte elements as input.
On POSIX systems, the code was incorrectly comparing bytes written against element count instead of byte count, causing data truncation for large inputs with non-byte element types.
Changes:
subprocess.Popen.communicate()
behavior between Windows and Posix on non-byte memoryview input #134453