Hung readline on pipe
Sean Dunn
sdunn at digitalanvil.com
Sat Feb 19 17:04:47 EST 2000
I'm using pipe2 to spawn a process and read it's stdout.. I do the
following, yet it still hangs. Any observations?:
# Initialization part : Bipipe is an interface to pipe2.. just pretend.
#
cmd = 'generateInfo'
inst = bipipe.BiPipe(cmd, '', 1)
(self.mPipeOut, self.mPipeErrOut, self.mPipeIn, self.mPipePID) =
(inst.fromchild, inst.childerr, inst.tochild, inst.pid)
fcntl.fcntl(self.mPipeOut.fileno(), FCNTL.F_SETFD, FCNTL.O_NDELAY)
fcntl.fcntl(self.mPipeErrOut.fileno(), FCNTL.F_SETFD, FCNTL.O_NDELAY)
# This part is actually in a separate function.. It reads input until
there's nothing on the pipe,
# and then breaks to do other processing, but will come back to this
section later.
#
while 1:
(readList, writeList, exList) = select.select([self.mPipeOut,
self.mPipeErrOut], [], [], 0)
if not readList:
break
#if
for item in readList:
char = item.read(1)
self.CollectByte(char)
#for
#while
At first it seems to work fine. The while 1: loop runs, gets input,
breaks out, etc. But I think when the child process exits, and there is
still stuff in the pipe to be read (before the while 1: gets around to
it) it hangs on the read() even though the select thinks there is
something there.. I have verified that the command I'm running
generates more than is being shown. I was using a full readline()
before the read() thinking that maybe it was just hanging on looking for
a \n, but it still doesn't work.
Any ideas on how to cure this?
Thanks!
Sean
--
Sean Dunn "I'm afraid. I'm afraid, Dave.
Digital Anvil Dave, my mind is going. I can feel it.
VFX Software Engineer I can feel it. I can feel it."
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20000219/6af5c4ac/attachment.html>
More information about the Python-list
mailing list