gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

anntzer.lee at gmail.com anntzer.lee at gmail.com
Sat Aug 31 20:03:41 EDT 2013


Hi,

At startup, IPython (qtconsole) calls "socket.gethostbyname_ex(socket.gethostname())[2]" to find a list of IP addresses that point to the machine. On a Linux server that I manage this call is extremely slow (>20s)... which I have trouble understanding as "ip addr show" seems to give the same information nearly instantaneously. Is there anything I can do to make this faster? Can this be a network configuration issue (I am behind a router)?

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

Thanks.

Antony



More information about the Python-list mailing list