Problems with read_eager and Telnet

Terry Reedy tjreedy at udel.edu
Mon Feb 28 13:32:03 EST 2011


On 2/28/2011 10:54 AM, Robi 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.

Given that FlightGear is a graphical flight simulator
http://www.flightgear.org/
https://secure.wikimedia.org/wikipedia/en/wiki/FlightGear
using a text terminal connection seems a bit odd,
unless using it just to get/set configuration,
in which case, speed should hardly seem an issue.
>
> 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 presume you are using read_until(b'\n').
read_until cannot return any faster than the server sends complete lines

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

read_eager is for when you want to parse the bytes yourself, such as 
when they come in a continuous stream without newline or other obvious 
separators. It will not return b'\n' any faster than read_until. It will 
simply give you your output lines in little bits that you would have to 
reassemble yourself.

> 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()?

Read the source Lib/telnetlib.py (as I just did). It is pretty 
straightforwad code.

-- 
Terry Jan Reedy




More information about the Python-list mailing list