[Tutor] Where does the program pointer go when...
Dave (NK7Z)
dave at nk7z.net
Wed Mar 1 00:16:00 EST 2023
Dennis,
Thanks you for the information, you answered my timeout-- where does it
go, question. Plus the references to the RFCs... THANK YOU!
I see you have a ham ticket, as I do, this script logs into an AR
cluster, and watches the incoming data stream... Parses it, and alerts
me to calls I have tagged to look for...
Your answers have been very helpful, again, thank you sir!!!
73, and thanks,
Dave (NK7Z)
https://www.nk7z.net
ARRL Volunteer Examiner
ARRL Technical Specialist, RFI
ARRL Asst. Director, NW Division, Technical Resources
On 2/28/23 20:38, Dennis Lee Bieber wrote:
> On Tue, 28 Feb 2023 10:26:58 -0800, "Dave (NK7Z)" <dave at nk7z.net> declaimed
> the following:
>
>> I am trying to get my head around what is a timeout, and what happens
>> when one occurs. I have a working script that does what I want, but I
>> am now working on trapping errors. i.e. Ethernet dies, telnet server
>> shuts down, telnet server just stops sending data, telnet server starts
>> sending b'', etc.
>>
>
> The library reference manual is a crucial resource.
>
>> As a result of this effort, I find I have a failed understanding of what
>> happens when a TIMEOUT occurs. I am fairly sure I don't even know WHAT
>> a TIMEOUT is... See assumptions list later.
>>
>
> """
> Telnet.read_until(expected, timeout=None)
>
> Read until a given byte string, expected, is encountered or until
> timeout seconds have passed.
>
> When no match is found, return whatever is available instead, possibly
> empty bytes. Raise EOFError if the connection is closed and no cooked data
> is available.
> """
>
> Note: "return whatever is available"... Often one buffers the partial
> data and retries the operation, combining partials until the complete data
> has been transferred or some more serious error occurs.
>
>>
>> Script above here initing all variables, etc...
>>
>> try:
>> result = tn.read_until(b"\r\n", TIMEOUT)
>
> ... which could mean you get stuff up to a <cr> but not the <lf>, or
> anything else that might have been sent.
>
>> if result == b'':
>> relogin()
>> configureCluster()
>> exitscript()
>
> Uhm... why "relogin" if you are just going to exit the program?
>
>> except socket.error: # If socket error-- exit with error.
>> logdata = 'Socket Error in watchstream(), at main read loop.'
>> logit(logdata)
>> exitscript()
>> except EOFError:
>> failcode = 6
>> logdata = 'EOF at main read loop.'
>> logit(logdata)
>> exitscript()
>> except OSError:
>> logdata = 'OS Error in watchstream().'
>> logit(logdata)
>> exitscript()
>>
>> Rest of script...
>>
>> I have at least two assumptions I want to check here:
>>
>> 1. TIMEOUT is defined as when when the telnet server just stops
>> spending data, but the telnet connection still exists, and TIMEOUT is
>> exceeded. i.e. the far side data collection died, but left the server
>> connected to my client. Is this correct?
>
> No... The far side just doesn't have data to send... Imagine that the
> far side is sending stuff being typed in by a user at a console (in
> non-buffered mode). The user walks away to get a cup of coffee, and your
> end times out with whatever the user last entered. Then they come back and,
> maybe, enter a few more characters and hit <enter>.
>
>>
>> 2. I assume the run pointer, (where the next instruction is run), just
>> drops down to the "Rest of script..." and the run continues, if TIMEOUT
>> is reached. Is this correct?
>>
>
> On timeout, the next statement executed will be the "if result == b'':"
>>
>> Any help would be appreciated, I am new to Python... I have looked all
>
> This is not really Python specific -- you probably need to study the
> BSD TCP socket protocol, and maybe telnet protocol(s)
> https://www.rfc-editor.org/rfc/rfc854
> https://www.rfc-editor.org/rfc/rfc5198
>
>> over and have not located anything that tells me what a TIMEOUT is
>> exactly. Is it if the telnet server drops, is it if the data flow
>> stops, but the telnet server is still connected, etc...
>
> For .read_until(), a closed connection raises EOFError. It may not be
> immediately detected (at the socket layer, there may be a buffer containing
> multiple lines of text and your .read_until() needs to empty that buffer
> before an actual socket read is next attempted).
>
>
More information about the Tutor
mailing list