gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

Roy Smith roy at panix.com
Sun Sep 1 06:57:37 EDT 2013


In article <48c8f8ca-d8c1-4a60-ba7f-8e8b00993f15 at googlegroups.com>,
 anntzer.lee at gmail.com wrote:

> It is the call to gethostbyname_ex that is very slow.  The call to 
> gethostname is quick (and returns the same string as /usr/bin/hostname).

First, please stop posting with Google Groups.  It makes a total mess of 
the quoted text.

Next, what happens when you use the command-line tools (nslookup or dig) 
to translate your hostname to an IP address, and what happens if you 
then try to reverse translate that IP address back to a name?

> This issue is independent of IPython:
> 
> $ time python -c 'import socket; 
> print(socket.gethostbyname_ex(socket.gethostname())[2])' 
> ['192.168.0.102']
> python -c   0.07s user 0.02s system 0% cpu 28.190 total

The real point is not that it's independent of IPython, it has nothing 
to do with Python at all.  What you've got here is a network 
configuration issue.  You would do better to recreate this problem with 
the native OS command line tools and then ask about it on a forum 
dedicated to your operating system.



More information about the Python-list mailing list