Friday, 23 August 2013

Python: select() returns immediately without no data to read (telnetlib)

Python: select() returns immediately without no data to read (telnetlib)

I want to use select.select() to block the loop until some data is ready
to be readed from a list of telnet sessions. However, the below code does
not work and the call to "select.select()" returns inmediatly with no data
to read. I'm using python 2.7.3 under Ubuntu 10.4.
tn = telnetlib.Telnet(IP,23,TIMEOUT)
# [... logging and password omitted ..]
while True:
logging.info("%d - waiting on select for data" % self.id)
read_ready, write_ready, expt_ready = select.select([ tn.get_socket()
],[],[])
logging.info("%d - select returned" % self.id)
if len(read_ready) == 1:
data = tn.read_eager()
logging.info("%d read %d characters" % (self.id, len(data)))
# ... continue processing the data...
An example of the output:
2013-08-23 10:37:28,634 - INFO: 1 - waiting on select for data
2013-08-23 10:37:28,672 - INFO: 1 - select returned
2013-08-23 10:37:28,673 - INFO: 1 read 0 characters
2013-08-23 10:37:28,833 - INFO: 1 - waiting on select for data
2013-08-23 10:37:28,874 - INFO: 1 - select returned
2013-08-23 10:37:28,874 - INFO: 1 read 0 characters
2013-08-23 10:37:29,029 - INFO: 1 - waiting on select for data
2013-08-23 10:37:29,073 - INFO: 1 - select returned
2013-08-23 10:37:29,074 - INFO: 1 read 0 characters

No comments:

Post a Comment