python - readlines will always block the caller -
i'm reading programming python mark lutz, , came across bit:
for pipe objects, effect of iterators may more useful avoiding loading entire result memory @ once: readlines block caller until spawned program finished, whereas iterator might not.
what mean?
if consider subprocess.popen
example. if call command outputs lot of data subprocess.pipe
calling proc.stdout.readlines()
wait until command finishes.
where if use iter
for line in iter(proc.stdout.readline,"")
, see output in real time , avoid having store output in memory.
if had process each line of output make more sense process line line input came in using iter
allows opposed blocking until command terminates using readlines
.
Comments
Post a Comment