[issue1907] Httplib.py not supporting timeout - Propose Fix attached

Guillaume Nourry-Marquis report at bugs.python.org
Tue Jan 22 16:57:57 CET 2008


New submission from Guillaume Nourry-Marquis:

The httplib file wasn'T supporting a timeout feature which was essential
for my load testing application I built. In order to do that, I had to
append a parameter to the connect function, which takes a socket timeout
value integer in seconds.

    def connect(self,timeout=None):
        """Connect to the host and port specified in __init__."""
        msg = "getaddrinfo returns an empty list"
        for res in socket.getaddrinfo(self.host, self.port, 0,
                                      socket.SOCK_STREAM):
            af, socktype, proto, canonname, sa = res
            try:
                self.sock = socket.socket(af, socktype, proto)
		#Guillaume's timeout
		self.sock.settimeout(timeout)
                if self.debuglevel > 0:
                    print "connect: (%s, %s)" % (self.host, self.port)
                self.sock.connect(sa)
            except socket.error, msg:
                if self.debuglevel > 0:
                    print 'connect fail:', (self.host, self.port)
                if self.sock:
                    self.sock.close()
                self.sock = None
                continue
            break
        if not self.sock:
            raise socket.error, msg

Simple patch, but it was essential for my work.

----------
components: Library (Lib)
files: httplib.py
messages: 61512
nosy: xlash
severity: minor
status: open
title: Httplib.py not supporting timeout - Propose Fix attached
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file9263/httplib.py

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1907>
__________________________________


More information about the Python-bugs-list mailing list