Interprocess comunication

Peter Otten __peter__ at web.de
Thu Jun 7 13:42:31 EDT 2012


Julio Sergio wrote:

> J. Cliff Dyer <jcd <at> sdf.lonestar.org> 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:

"""
Warning
 
Use communicate() rather than .stdin.write, .stdout.read or .stderr.read 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