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.
I had a similar problem. It happened that my hostname was
localhost.localdomain
, being lazy when installing the OS.The solution was to give it a sane name by
sudo vi /etc/hostname
and changing it to myname.mydomain and now it runs in 1s.