Very slow opening of client connections to localhost with httplib

Peter Hansen peter at
Fri Dec 12 20:05:04 CET 2003

Martin Fuzzey wrote:
> To test this I did :
> import socket
> socket.getaddrinfo("localhost", 10000, 0, socket.SOCK_STREAM)
> and sure enough it blocked for several seconds before finally
> returning
> However
> socket.gethostbyname("localhost")
> returns immediately

Any chance your /etc/host.conf, /etc/resolv.conf or /etc/hosts files 
are buggering this up somehow?  (It doesn't explain gethostbyname() 
returning immediately, unless perhaps that function internally handles 
localhost "magically".)  Just a thought.

In my experience, delays like this generally result from host.conf
having "order bind,hosts" instead of the other way around, plus perhaps
an inappropriate "options timeout:xxx" value in resolv.conf.  

I haven't ever seen an issue with localhost, however, but I've never
been on a machine that didn't have the right entry in /etc/hosts.


More information about the Python-list mailing list