[Tutor] Where does the program pointer go when...

Dave (NK7Z) dave at nk7z.net
Tue Feb 28 13:26:58 EST 2023


Hello,

First let me think you all for being here to answer questions from folks 
having difficulty.

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.

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.

The snippit below is designed to read one line from a telnet stream that 
never ends, looking for a \n, as the end of a line, while looking to 
trap errors, and leave me a message as to what failed via 
logit(logdata).  logit() just writes some data for me to read postmortem.

relog() waits 10 minutes, then tries to relog into the telnet server.
At this point I am NOT trying to relog into the server, I am testing to 
be sure my understanding of the fail modes is correct.

exitscript() just kills the script, leaving the log file for me to look 
at, to decide what happened to kill things...


Script above here initing all variables, etc...

         try:
             result = tn.read_until(b"\r\n", TIMEOUT)
             if result == b'':
                 relogin()
                 configureCluster()
                 exitscript()
         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?

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?

I am trying to trap all errors, and recover cleanly from them while not 
hammering the far side telnet server with login attempts...

Until I have this working, I have all errors kill my script, not trigger 
a relogin.  That way nothing gets loose in a relog/fail loop.

Any help would be appreciated, I am new to Python...  I have looked all 
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...

Any help would be appropriated...

-- 
73, and thanks,
Dave (NK7Z)
https://www.nk7z.net
ARRL Volunteer Examiner
ARRL Technical Specialist, RFI
ARRL Asst. Director, NW Division, Technical Resources


More information about the Tutor mailing list