-
Notifications
You must be signed in to change notification settings - Fork 15
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
Fix stdin bug #158
Fix stdin bug #158
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not so sure about this fix. Explicitly checking all the cases in which we should not re-open the file in _file_is_socket_or_pipe
feels fragile. Is it correct that the two open()
calls occur in _open_stdin_or_out
? Then an alternative solution would be to just not use open()
there, but to just return the already open sys.stdout.buffer
or sys.stdin.buffer
. Would that work?
I agree. When allowing file-like objects, my first design was to convert everything into a binary stream, then work from there. Multiple calls to the _open_as_binary_stream function solved this, but caused this problem. However I think I might alleviate this by using a cache. That would be much less flaky than this current solution. |
A cache makes the code more messy. Pipes that are passed as files on linux (such as "/dev/stdin") need to be treated differently than regular files. The only way to do so is to have the stat code. By doing it this way the format detection can be kept. I agree that it feels fragile in that not all edge cases are covered, but on the other hand checking for ports, sockets and pipes should be pretty much all the use cases. EDIT: I added an explicit "/dev/stdin" test first, then started to mess around to see if there was a better way, but that kept breaking the /dev/stdin test, so I have given up on finding a better way :-). |
I have replaced all the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome with the extensive tests!
Fixes #157
I also added a whole lot of tests to ensure piped reading never breaks again! (Hopefully)