On Thu, Feb 03, 2011 at 04:37:33PM -0700, Todd Millecam wrote:
>
> myProc = subprocess.Popen(["server.bin"], stderr=subprocess.PIPE,
> stdin=subprocess.PIPE)
>
> while True:
> inStreams, outStreams, errStreams =
> select.select([myProcess.stderr,sys.stdin],[],[])
> for stream in inStreams:
> data = stream.read()
> doAction(data)
> stream.flush()
>
> Without the subprocess module in this, it works as expected (I can use
> select on stdin and sys.stderr for example). As soon as I use the
> subprocess file descriptor, it never closes or gets back to an "unready"
> state.
1) You might add some print statements to see how often you're actually
calling select() and read(). Unless you explicitly set your streams to
unbuffered mode, read() without arguments should try to read until EOF
(see pydoc file.read), which doesn't play well with select. I'm not
sure if this is actually your problem, but it's something to pay
attention to.
2) If select is really being called over and over, what is the value of
data in the loop? If it's the empty string, then the stream is trying
to tell you that it's reached EOF and needs to be closed. You should
probably add:
if not data:
stream.close()
just after the line with stream.read().
3) You shouldn't need to flush streams that you're reading from. That's
an operation for writing.
4) I noticed that the Popen sets a pipe for stdin but not actually
writing to myProcess.stdin. This wouldn't cause the exact symptom that
you're seeing, but there are a few cases where deadlock can occur when
reading and writing aren't both in the select loop.
Just a few thoughts. Do any of these help?
--
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868
--------------------
BYU Unix Users Group
http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list