Bugs item #1252001, was opened at 2005-08-04 11:47
Message generated for change (Comment added) made by padded
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1252001&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: padded (padded)
Assigned to: Nobody/Anonymous (nobody)
Summary: Issue with telnetlib read_until not timing out

Initial Comment:
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)
        self.process_rawq()
        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 select.select(*s_args)
== s_reply:
            i = max(0, len(self.cookedq)-n)
            self.fill_rawq()
            self.process_rawq()
            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.
                time.sleep(1)
                timeoutcounter+=1
                if(timeoutcounter>timeout):
                  buf=self.cookedq
                  self.cookedq = ""
                  return buf
        return self.read_very_lazy()

----------------------------------------------------------------------

>Comment By: padded (padded)
Date: 2005-08-04 11:52

Message:
Logged In: YES 
user_id=1324012

note that you need to import time for this to work

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1252001&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to