Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken pipe: recognize "intentionally" closed streams #52

Open
2 tasks
neithere opened this issue Jan 4, 2014 · 0 comments
Open
2 tasks

Broken pipe: recognize "intentionally" closed streams #52

neithere opened this issue Jan 4, 2014 · 0 comments

Comments

@neithere
Copy link
Owner

neithere commented Jan 4, 2014

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
@neithere neithere changed the title Broken pipe Broken pipe: recognize "intentionally" closed streams Jul 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant