mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Fix memoryview and closed stdin handling in _communicate_streams_posix
Apply the same fixes from Popen._communicate() to _communicate_streams_posix for run_pipeline(): 1. Handle non-byte memoryview input by casting to byte view (gh-134453): Non-byte memoryviews (e.g., int32 arrays) had incorrect length tracking because len() returns element count, not byte count. Now cast to "b" view for correct progress tracking. 2. Handle ValueError on stdin.flush() when stdin is closed (gh-74389): Ignore ValueError from flush() if stdin is already closed, matching the BrokenPipeError handling. Add tests for memoryview input to run_pipeline: - test_pipeline_memoryview_input: basic byte memoryview - test_pipeline_memoryview_input_nonbyte: int32 array memoryview Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d420f29e2b
commit
df8f082f59
2 changed files with 54 additions and 2 deletions
|
|
@ -540,6 +540,10 @@ def _communicate_streams_posix(stdin, input_data, read_streams,
|
|||
stdin.flush()
|
||||
except BrokenPipeError:
|
||||
pass
|
||||
except ValueError:
|
||||
# ignore ValueError: I/O operation on closed file.
|
||||
if not stdin.closed:
|
||||
raise
|
||||
if not input_data:
|
||||
try:
|
||||
stdin.close()
|
||||
|
|
@ -547,8 +551,14 @@ def _communicate_streams_posix(stdin, input_data, read_streams,
|
|||
pass
|
||||
stdin = None # Don't register with selector
|
||||
|
||||
# Prepare input data
|
||||
input_view = memoryview(input_data) if input_data else None
|
||||
# Prepare input data - cast to bytes view for correct length tracking
|
||||
if input_data:
|
||||
if not isinstance(input_data, memoryview):
|
||||
input_view = memoryview(input_data)
|
||||
else:
|
||||
input_view = input_data.cast("b") # byte view required
|
||||
else:
|
||||
input_view = None
|
||||
|
||||
with _PopenSelector() as selector:
|
||||
if stdin and input_data:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue