I'm having trouble understanding why the print statement in the code produces output immediately.
import subprocess
proc = subprocess.Popen(['python3', '-i'], stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
_ = proc.stdin.write(b'2+2\n')
_ = proc.stdin.flush()
print(proc.stdout.readline())
# produces b'4\n' immidiately!
proc.terminate()
proc.wait(timeout=0.2)
Shouldn't the child 'python -i''s stdout be fully buffered as it is writing to a pipe? Meaning, I should not see the output in the print statement until the child terminates, or the child's stdout buffer becomes full and is explicitly flushed to the os?
Interesting, the same behavior on the terminal- output seen after an 'enter'. Perhaps 'python -i' flushes output after a '\n'?
ā ~ python3 -i -c 'print("hiiiii")' | cat
>>>
>>> hiiiii
>>> ^D```