I've seen this question asked here, but the answers given did not work in my case and was marked duplicate.
python -u
does not work forstdin
in Python 3.sys.stdin = sys.stdin.detach()
throws aValueError: underlying buffer has been detached
.- None of these work for non-
stdin
inputs and other files being used as stream. - Adding a hook does not work:
FileInput(openhook=hook_nobuf)
and usingopen(buffering=0)
in the hook.
I dug in the source code (/usr/lib/python3.2/fileinput.py
) and saw that readlines(bufsize)
was being used internally to load a buffer. No shell or other piping shenanigans.