[Python-Dev] [ Bug #110676 ] fd.readlines() hangs (via popen3) (PR#385)
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Wed, 20 Sep 2000 22:50:30 +0200
I've closed your report at
http://sourceforge.net/bugs/?func=detailbug&bug_id=110676&group_id=5470
That is a bug in the application code. The slave tries to write 6000
bytes to stderr, and blocks after writing 4096 (number measured on
Linux, more generally, after _PC_PIPE_BUF bytes). The server starts
reading on stdin, and blocks also, so you get a deadlock. The proper
solution is to use
import popen2
r,w,e = popen2.popen3 ( 'python slave.py' )
e.readlines()
r.readlines()
r.close()
e.close()
w.close()
as the master, and
import sys,posix
e = sys.stderr.write
w = sys.stdout.write
e(400*'this is a test\n')
posix.close(2)
w(400*'this is another test\n')
as the slave. Notice that stderr must be closed after writing all
data, or readlines won't return. Also notice that posix.close must be
used, as sys.stderr.close() won't close stderr (apparently due to
concerns that assigning to sys.stderr will silently close is, so no
further errors can be printed).
In general, it would be better to use select(2) on the files returned
from popen3, or spread the reading of the individual files onto
several threads.
Regards,
Martin