Interprocess comunication

Peter Otten __peter__ at
Thu Jun 7 19:42:31 CEST 2012

Julio Sergio wrote:

> J. Cliff Dyer <jcd <at>> writes:
>> readlines() reads all the lines from the filehandle, but the filehandle
>> hasn't signalled that it is done writing lines, so fo is waiting until
>> fi is complete.  You either need to keep reading one line at a time, and
>> manually release control when there's nothing more to read, or you need
>> to do an fi.close() before you try to use fo.readlines().
> Thanks... It worked as you said. Here is how I coded it:
> ->>> fi.writelines(["uno\n","dos\n","tres\n"])
> ->>> fi.close()
> ->>> l = fo.readlines()
> ->>> l
> ['uno\n', 'dos\n', 'tres\n']

I believe this may hang on the fi.writelines(...) line if you write "too 
much" data.

>From the subprocess documentation:

Use communicate() rather than .stdin.write, or to 
avoid deadlocks due to any of the other OS pipe buffers filling up and 
blocking the child process.

More information about the Python-list mailing list