views:

259

answers:

2

After I begin the polling loop, all messages printed after the first iteration require me to press enter in the terminal for it to be displayed.

#!/usr/bin/python
import socket, select, os, pty, sys

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 5007))
s.listen(5)

mypoll = select.poll()
mypoll.register(s.fileno() )

while True:
    print "poll time"
    subr = mypoll.poll()
    for x in subr[0]:

        if x == s.fileno():
            conn, addr = s.accept()

            pid, fd = pty.fork()
            if pid != 0:
                mypoll.register(fd)
                print "done. go back to poll now"
            else:
                print "forked"
                #handles new connection

        else:
            data = os.read(x,1024)
            print data
A: 

After the first iteration, haven't you registered the pty fd, and are then polling it? And its fd will never be equal to the socket fd, so you will then os.read the pty fd. And isn't that now reading from your terminal? And so won't typing a return cause it to "print data"?

DigitalRoss
All the fd's should be going to the Final else statement, but only after they have data for me to read in.
sandrsandr12
A: 

Never mind, i fixed it.

sandrsandr12