Problems with read_eager and Telnet

Jack Diederich jackdied at gmail.com
Mon Feb 28 11:12:22 EST 2011


On Mon, Feb 28, 2011 at 10:54 AM, Robi <roberto.inzerillo at gmail.com> wrote:
> Hi everybody,
>  I'm totally new to Python but well motivated :-)
>
> I'm fooling around with Python in order to interface with FlightGear
> using a telnet connection.
>
> I can do what I had in mind (send some commands and read output from
> Flightgear using the telnetlib) with a read_until() object to catch
> every output line I need, but it proved to be very slow (it takes 1/10
> of a sec for every read_until().
>
> I tried using the read_eager() object and it's waaaayyyy faster (it
> does the job in 1/100 of a sec, maybe more, I didn't tested) but it
> gives me problems, it gets back strange strings, repeated ones,
> partially broken ones, well ... I don't know what's going on with it.
>
> You see, I don't know telnet (the protocol) very good, I'm very new to
> Python and Python's docs are not very specific about that read_eager(9
> stuff.
>
> Could someone point me to some more documentation about that? or at
> least help me in getting a correct idea of what's going on with
> read_eager()?

Telnet sends two kinds of data over the same channel (a simple TCP
stream).  It sends the bytes you actually see in your terminal and it
sends control commands that do things like turn echo on/off and
negotiate what terminal type to use.  Each time telnetlib reads from
the socket it puts the control stuff in one bucket and stores the
plain text in a buffer to return from all the read_* commands.

read_eager() returns the plain text that has already been read from
the socket.  That might be a partial line.  It won't try to read from
the socket to get a full line.  That's why it is fast, because it
never does I/O.

-Jack



More information about the Python-list mailing list