Skip to content

Handle closed output pipes without a traceback - #248

Open
2836048681 wants to merge 1 commit into
neithere:masterfrom
2836048681:fix/52-handle-broken-output-pipes
Open

2836048681 wants to merge 1 commit into
neithere:masterfrom
2836048681:fix/52-handle-broken-output-pipes

Conversation

@2836048681

Copy link
Copy Markdown

Fixes #52.

When a consumer such as head closes its end of a pipeline, Argh currently
raises BrokenPipeError while writing a command's results. Small outputs can
fail later, during Python's shutdown flush, and print an ignored exception.

Catch BrokenPipeError around output writes and flushes, stop consuming further
results, and close the broken stream to prevent another flush at shutdown.
Flush buffered output when dispatching finishes so small results take the same
error-handling path. Keep command execution and result string conversion outside
the exception handler; their errors and unrelated output errors still propagate.

Add regressions for writes, newlines, per-line and final flushing, cleanup after
a failed close, raw output, and exception propagation. Four subprocess cases
exercise real closed pipes with small and large results and both flush modes.
Document the output-stream behavior and add a changelog entry.

Validation

  • All 170 existing tests passed on the unchanged source.
  • All 14 new bug regressions failed before the fix.
  • Full suite after the fix: 189 passed, 100% coverage, one existing
    namespace deprecation warning. Linux, Python 3.12.3, pytest 9.2.0.
  • A real Argh-to-head -n 10 pipeline changed from producer exit 1 with a traceback
    to producer/consumer exit 0 with exactly ten output lines and empty stderr.
  • Ruff 0.15.20 lint and format checks passed for the changed Python files.
  • MyPy 1.8.0 with --ignore-missing-imports passed for all 24 source/test files.
  • git diff --check passed.

To rerun the full tests from the checkout:

../.venv/bin/python -m pytest --cov=argh --cov-report=term-missing --cov-fail-under=100 tests

Supervisor handoff

  • Repository: https://github.com/neithere/argh (384 stars when screened).
  • Issue: open, unassigned, zero comments; labeled bug and component-dispatching.
  • Branch: fix/52-handle-broken-output-pipes.
  • Commit: 9e9b820fd0244977b770e4503cbec84238edce01.
  • Base: master, 8d25286693d5b35e7348bbac1521e286aac85c01; clone made with git clone --depth 1.
  • Checkout: /home/hatch/workspace/pr-factory/work/w01-r93/repo.
  • Files: src/argh/dispatching.py, tests/test_dispatching.py, CHANGELOG.rst.
  • Screening: 21 new eligible issues in shortlist.md; prior completed worker-01
    repositories excluded. No PREV-LEDGER.md was present.
  • Final overlap check: issue open/unassigned with no comments; no matching PR in
    the all-state issue-number/broken-pipe search or the 12 open repository PRs.
    The owner-open-PR search returned zero.
  • Evidence: evidence/ and screening/; review package: ready/argh-52/.
  • Local commit only. Nothing pushed, submitted, commented, or claimed; no GitHub
    authentication used.

Placement limitation: ../ready-w01-r93.md, ../LEDGER-w01.md, and the
factory-wide ready/ledger destinations are outside the writable root on a
read-only mount. This draft and LEDGER-w01.md are complete local handoff copies
for supervisor placement. Mount evidence is in evidence/handoff-paths.json.

Check scope: project-pinned pre-commit environments and the Python/OS CI matrix
were not run. The passing Ruff/MyPy versions are stated above. An exploratory
MyPy 2.1.0 run without ignore flags reports the same two diagnostics on this
change and the untouched base (optional argcomplete import and an existing
argparse override); both logs are in evidence/.

Fixes #52.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken pipe: recognize "intentionally" closed streams

1 participant