Skip to content

gh-47798: Refactor the POSIX subprocess.Popen._communicate selector loop into helpers#149032

Merged
gpshead merged 1 commit intopython:mainfrom
gpshead:gh-47798-extract-communicate-helpers
Apr 27, 2026
Merged

gh-47798: Refactor the POSIX subprocess.Popen._communicate selector loop into helpers#149032
gpshead merged 1 commit intopython:mainfrom
gpshead:gh-47798-extract-communicate-helpers

Conversation

@gpshead
Copy link
Copy Markdown
Member

@gpshead gpshead commented Apr 27, 2026

No public API change. Lift the per-iteration select/read/write loop out of Popen._communicate (POSIX) into a module-level _communicate_io_posix(), with small _flush_stdin / _make_input_view / _translate_newlines helpers alongside it. Popen._communicate calls the helper and persists the returned input offset for resume-after-timeout.

Retire the private Popen._remaining_time method (it never used self & nothing overrides it) in favor of module-level _deadline_remaining; all call sites updated.

Defensive behavioural deltas: the stdin and stdout/stderr .close() calls in the I/O loop now swallow BrokenPipeError / OSError, matching __exit__ and the no-input path; previously these were bare.

Adds test_communicate_timeout_resume_partial_write to cover _input_offset bookkeeping across TimeoutExpired/resume.

... why tied to this issue? it's a useful pure refactor before the larger feature work.

…ctor loop into helpers

No public API change.  Lift the per-iteration select/read/write loop out of
Popen._communicate (POSIX) into a module-level _communicate_io_posix(), with
small _flush_stdin / _make_input_view / _translate_newlines helpers alongside
it.  Popen._communicate calls the helper and persists the returned input
offset for resume-after-timeout.

Retire the private Popen._remaining_time method in favor of module-level
_deadline_remaining; all call sites (POSIX and Windows) updated.

Defensive behavioural deltas: the stdin and stdout/stderr .close() calls in
the I/O loop now swallow BrokenPipeError / OSError, matching __exit__ and the
no-input path; previously these were bare.

Adds test_communicate_timeout_resume_partial_write to cover _input_offset
bookkeeping across TimeoutExpired/resume.
@gpshead
Copy link
Copy Markdown
Member Author

gpshead commented Apr 27, 2026

If we ever wanted to for maintenance reasons this could be backported (though I'd leave the silly Popen._remaining_time method in place when doing so). It's a straightforward refactor so anything that needs backporting through in absense of this should remain understandable regardless.

@gpshead gpshead enabled auto-merge (squash) April 27, 2026 00:21
@gpshead gpshead merged commit 2754e9a into python:main Apr 27, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant