Skip to content

Commit d56fd9c

Browse files
gpsheadclaude
andcommitted
gh-162016: Address review; clarify the NEWS entry
Use "is not None" when restoring stdin's blocking mode, matching the check made before the try block. Reword the NEWS entry to say that this works around a macOS and FreeBSD kernel bug that appears under system-wide pipe buffer memory pressure, most likely on loaded hosts with many pipes in use. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 7c5985b commit d56fd9c

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎Lib/subprocess.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ def _communicate(self, input, endtime, orig_timeout):
24742474
close_on_eof=True)
24752475
finally:
24762476
# Leave stdin as the user expects it after a timeout.
2477-
if stdin_to_write and not stdin_to_write.closed:
2477+
if stdin_to_write is not None and not stdin_to_write.closed:
24782478
os.set_blocking(stdin_to_write.fileno(), True)
24792479
# Persist the returned offset on self so a subsequent
24802480
# communicate() after a TimeoutExpired resumes mid-input
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
Fix :meth:`subprocess.Popen.communicate` on POSIX blocking past its
2-
*timeout* when :func:`select.poll` reports the child's stdin pipe as
3-
writable while the pipe is full, as seen on some macOS versions. Stdin is
4-
now non-blocking while :meth:`!communicate` writes to it.
1+
Work around a macOS and FreeBSD kernel bug that could make
2+
:meth:`subprocess.Popen.communicate` hang or block past its *timeout*.
3+
When the operating system is under system-wide pipe buffer memory pressure,
4+
:func:`select.poll` and :func:`select.select` can report the child's stdin
5+
pipe as writable when a write to it would block. This was most likely to be
6+
seen on loaded hosts with many pipes in use at once. :meth:`!communicate`
7+
now keeps stdin non-blocking while it writes to it and retries after a short
8+
delay when the pipe turns out to be full.

0 commit comments

Comments
 (0)