Bound the reader-thread joins in Command - #3
Merged
Merged
Conversation
added 2 commits
September 16, 2026 10:30
A grandchild that inherits the pipes keeps them open after the child exits, so an unbounded join waited on a process nobody tracked.
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Luis Placid.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Command.wait()joins its stdout and stderr reader threads with no timeout. A grandchild process that inherited the pipes keeps them open after the child exits, so the readers never see EOF andwait()blocks indefinitely, well past its owntimeoutargument.Fix
reader_join_timeout, default 10s.readers_abandonedrecords that a join gave up, so a caller can tell.__exit__'s error path bounds the same two joins.Scope
The reader threads are daemons and append to their output lists line by line, so giving up on them loses only trailing output from a process that is already being terminated. A clean exit still drains fully.
Testing
Two cases added to
examples/test_command.py: a child that leaves a grandchild on its stdout madewait(timeout=5)return after 12.1s before this change and 2.5s after, and a clean exit still drains withreaders_abandonedFalse. Full example suite: 32 passed, 3 skipped.