Am I misusing socket.setdefaulttimeout here?

Skip Montanaro skip at pobox.com
Thu Mar 20 23:37:25 CET 2003


    Syver> I was under the definite impression that timeoutsocket also
    Syver> worked by putting the socket in blocking mode. 

You meant non-blocking mode, yes?

    Syver> And httplib doesn't use the file interface to the socket library
    Syver> as far as I can remember. 

>From httplib.py:

class HTTPResponse:

    def __init__(self, sock, debuglevel=0, strict=0):
        self.fp = sock.makefile('rb', 0)
        ...

Then later:

    def _read_status(self):
        # Initialize with Simple-Response defaults
        line = self.fp.readline()

Later still:

    def read(self, amt=None):
        if self.fp is None:
            return ''

        if self.chunked:
            return self._read_chunked(amt)

        if amt is None:
            # unbounded read
            if self.will_close:
                s = self.fp.read()
            else:
                s = self._safe_read(self.length)
            self.close()        # we read everything
            return s

Need I continue? ;-)

    Syver> The point I am trying to make here is that I don't see why things
    Syver> that worked with timeoutsocker should stop working on the new
    Syver> socket with timeout mode.

Timeoutsocket implements a file-like abstraction (TimeoutFile) directly on
top of the socket without calling the socket's makefile method.  It
implements write, read, readline, readlines and flush methods.  I suspect
this would work for the socket module as well, though there are probably
some subtle semantic differences between how TimeoutFile the file-like
objects returned by sock.makefile operate.

Skip





More information about the Python-list mailing list