This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Issue with telnetlib read_until not timing out
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 2.6
Status: closed Resolution: out of date
Dependencies: 1360221 Superseder:
Assigned To: jackdied Nosy List: jackdied, padded
Priority: normal Keywords:

Created on 2005-08-04 15:47 by padded, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg60796 - (view) Author: padded (padded) Date: 2005-08-04 15:47
So, I looked through the read_until code and there is
no provision to jump out of the function and return
whatever its got so far if it reaches the timeout. 
This is a problem and so far I couldn't see anyone
giving people a clear reason why this is happening.  So
I added a few snippets of code to handle the timeout. 
So if you pass a timeout value along with the
read_until, it will timeout after that many seconds
(roughly). Here's my snippet of the code:
    def read_until(self, match, timeout=None):
        """Read until a given string is encountered or
until timeout.

        When no match is found, return whatever is
available instead,
        possibly the empty string.  Raise EOFError if
the connection
        is closed and no cooked data is available.
        Modified such that the timeout feature DOES
timeout when it
        needs to.

        n = len(match)
        i = self.cookedq.find(match)
        if i >= 0:
            i = i+n
            buf = self.cookedq[:i]
            self.cookedq = self.cookedq[i:]
            return buf
        s_reply = ([self], [], [])
        s_args = s_reply
        if timeout is not None:
            s_args = s_args + (timeout,)
        timeoutcounter=0 #added this, simple counter
for number of times we've slept
        while not self.eof and*s_args)
== s_reply:
            i = max(0, len(self.cookedq)-n)
            i = self.cookedq.find(match, i)
            if i >= 0:
                i = i+n
                buf = self.cookedq[:i]
                self.cookedq = self.cookedq[i:]
                return buf
            if timeout is not None:#this will handle
the timeout.
                  self.cookedq = ""
                  return buf
        return self.read_very_lazy()
msg60797 - (view) Author: padded (padded) Date: 2005-08-04 15:52
Logged In: YES 

note that you need to import time for this to work
msg85035 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2009-04-01 16:20
assigning all open telnetlib items to myself
msg85604 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2009-04-06 01:34
This was fixed in r47215
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42253
2009-04-06 01:34:42jackdiedsetstatus: open -> closed
resolution: out of date
messages: + msg85604
2009-04-01 16:20:46jackdiedsetassignee: jackdied

messages: + msg85035
nosy: + jackdied
2009-03-20 23:11:05ajaksu2setdependencies: + telnetlib expect() and read_until() do not time out properly, - Issue with telnetlib read_until not timing out
2009-03-20 23:11:05ajaksu2unlinkissue1252001 dependencies
2009-03-20 23:10:20ajaksu2setdependencies: + Issue with telnetlib read_until not timing out
2009-03-20 23:10:20ajaksu2linkissue1252001 dependencies
2009-02-16 00:45:36ajaksu2setstage: test needed
type: behavior
versions: + Python 2.6, - Python 2.4
2005-08-04 15:47:52paddedcreate