Skip to content

Commit a9e5ef9

Browse files
gpsheadclaude
andcommitted
gh-162016: Make comments stand on their own
Explain what stdin_paused_for holds, say why stdin's blocking mode is restored in terms of what later callers expect, and describe the test's blocking case without referring to "the fix". Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 8dc3b41 commit a9e5ef9

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎Lib/subprocess.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ def _communicate_io_posix(selector, stdin, input_view, input_offset,
291291
# Seconds to keep stdin out of the selector after a write that
292292
# would have blocked; 0 when stdin is registered or finished.
293293
stdin_backoff = 0
294+
# The previous such delay, which the next one doubles. A
295+
# successful write resets it.
294296
stdin_paused_for = _STDIN_BACKOFF_MIN / 2
295297

296298
while selector.get_map() or stdin_backoff:
@@ -2473,7 +2475,8 @@ def _communicate(self, input, endtime, orig_timeout):
24732475
endtime,
24742476
close_on_eof=True)
24752477
finally:
2476-
# Leave stdin as the user expects it after a timeout.
2478+
# Code that uses self.stdin after communicate() returns
2479+
# or times out expects writes to it to block.
24772480
if stdin_to_write is not None and not stdin_to_write.closed:
24782481
os.set_blocking(stdin_to_write.fileno(), True)
24792482
# Persist the returned offset on self so a subsequent

‎Lib/test/test_subprocess.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3604,8 +3604,8 @@ def select(self, timeout=None):
36043604
ready.append((key, selectors.EVENT_WRITE))
36053605
return ready
36063606

3607-
# The child does not read stdin, so the pipe fills up. Without the
3608-
# fix, write() blocks until the child exits.
3607+
# The child does not read stdin, so the pipe fills up. A blocking
3608+
# write() would not return until the child exits.
36093609
sleep = support.SHORT_TIMEOUT
36103610
with mock.patch.object(subprocess, '_PopenSelector',
36113611
AlwaysWritableSelector), \

0 commit comments

Comments
 (0)