> On Sep 24, 2016, at 15:49, Phil <[email protected]> wrote:
>
> On 25/09/16 01:01, David Rock wrote:
>>
>> when you say "the client is not responding, certainly not as expected”,
>> what, exactly, is the output you get?
>>
>
> In my dazed state I think I responded to David personally instead of the
> list, my apologies.
:-)
> Thank you for your reply David.
>
> This is what I expect:
>
> Trying 127.0.0.1...
> Connected to localhost.
> Escape character is '^]'.
>
> But, as I say, the console is blocked and nothing is returned.
>
> I'll try the debug method that you suggested.
So you are expecting to read until the header stanza is complete, then send a
command and presumably get the results of the command.
The problem is read_all() doesn’t work the way you think it does. See what
happens with your current code if you send ctrl+], it will probably print as
expected, but also close the connection. I don’t think read_all is the right
function for the task you are trying to perform.
You are putting it inside a print statement
print(tn.read_all())
but that’s never going to print anything or return control because read_all
will never finish (and never return to the print call). read_all() is a
blocking operation that’s going to sit there and keep trying to read data until
it’s told to stop (EOF), or until the connection times out. What you probably
mean to do is use read_until(). You know what you are expecting, so try to
catch it with something like:
header = tn.read_until("character is '^]’.”, timeout=5)
print(header)
tn.write("f" + "\n”)
etc
read_until looks for a specific string and returns when it finds it, giving
control back to you.
—
David Rock
[email protected]
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor