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.

classification
Title: Httplib.py not supporting timeout - Propose Fix attached
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: facundobatista, xlash
Priority: normal Keywords:

Created on 2008-01-22 15:57 by xlash, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
httplib.py xlash, 2008-01-22 15:57 modified version of httplib.py
Messages (2)
msg61512 - (view) Author: Guillaume Nourry-Marquis (xlash) Date: 2008-01-22 15:57
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.
msg61513 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-01-22 15:59
It's already fixed in the trunk (2.6 will have timeout for httplib and
other TCP libraries).
History
Date User Action Args
2022-04-11 14:56:30adminsetgithub: 46202
2008-01-22 15:59:48facundobatistasetstatus: open -> closed
resolution: out of date
messages: + msg61513
nosy: + facundobatista
2008-01-22 15:57:55xlashcreate