On Thu, Feb 03, 2011 at 06:58:26PM -0700, Todd Millecam wrote:
> Here's the actual code.  It pauses immediately after reaching the main
> loop--but after any input is recieved it enters an infinite loop.

I saw that you posted a workaround about running readline().
Unfortunately, readline blocks until it can read a whole line, so it
usually doesn't pair well with a select loop.  Stdin is usually line
buffered, but I don't think the pipe from Popen necessarily is.

One thing you might want to fix: your class is running main() from
__init__().  I would recommend limiting the constructor to just
initializing the object.  Whoever creates a mineServer can call the main
method.  In fact, I would probably even put the Popen call into main(),
too.

Anyway, I copy-and-pasted your code and then made some minor changes so
that I could run it.  I ended up with the following code, which I ran
with "cat /etc/group |python hello.py".  Unfortunately, I was not able
to reproduce the problem that you described.  I really am curious about
this issue, so let me know if you can find any other info.

import select
import subprocess
import sys


class MineServer(object):
    def __init__(self):
        #Start the server process
        self.SP = subprocess.Popen(['cat', '/etc/passwd'],
                stdout=subprocess.PIPE, stdin=subprocess.PIPE,
                stderr=subprocess.PIPE)
    
    def main(self):
        files = [sys.stdin, self.SP.stdout, self.SP.stderr]
        while files:
            inputReady, outputready, exceptReady = select.select(
                    files, [], [], 1)
            for IO in inputReady:
                line = IO.read(80)
                print 'line: "%s"' % line
                if not line:
                    IO.close()
                    files.remove(IO)

if __name__ == '__main__':
    s = MineServer()
    s.main()


-- 
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

Reply via email to