Skip to content

Broken pipe: recognize "intentionally" closed streams #52

@neithere

Description

@neithere

Observation

$ timetra find -a sleep -f 'foooooooooooooooooooooooooooooooooooooooooooo' | head
foooooooooooooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooooooooooooooo
foooooooooooooooooooooooooooooooooooooooooooo
Traceback (most recent call last):
  File "/home/andy/src/timetra/bin/timetra", line 7, in <module>
    main()
  File "/home/andy/src/timetra/timetra/cli.py", line 172, in main
    p.dispatch()
  File "/usr/lib/python3.3/site-packages/argh/helpers.py", line 53, in dispatch
    return dispatch(self, *args, **kwargs)
  File "/usr/lib/python3.3/site-packages/argh/dispatching.py", line 128, in dispatch
    io.dump(line, f)
  File "/usr/lib/python3.3/site-packages/argh/io.py", line 101, in dump
    output_file.write(data)
BrokenPipeError: [Errno 32] Broken pipe

Cause

When a (sufficiently long) line is written to an already closed stream, the BrokenPipeError is raised.

Problem

When the stream is closed, it is probably intentional. In the above case it is head that has closed the stream after getting 10 lines from argh. The exception should not be raised in this situation.

Solution

  • gather information: what exceptions are raised in this case in which conditions (Python version + stream type)
  • catch such exception and simply return

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions