I've the below piece of code to read data from a child process as its generated and write to a file.
from subprocess import Popen, PIPE
proc = Popen('..some_shell_command..', shell=True, stdout=PIPE)
fd = open("/tmp/procout", "wb")
while True:
data = proc.stdout.read(1024)
if len(data) == 0:
break
fd.write(data)
fd.close()
'Popen' default bufsize is 0 => unbuffered. What will happen if for some reason the write-to-file operation experiences a huge latency?
- Assuming that the child process is supposed to produce 500GB of data, do all those data get stored in memory until the parent reads them all? (OR)
- Will the child process wait for 1024 bytes of data to be read by the parent before writing the next 1024 bytes to stdout? (OR)
- Will the child process wait after the OS pipe buffer gets filled and once the parent reads, the child resumes writing again? (OR)
- ??