gethostbyname_ex(hostname)非常慢 [英] gethostbyname_ex(hostname) extremely slow

查看:153
本文介绍了gethostbyname_ex(hostname)非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在启动时,IPython(qtconsole)调用socket.gethostbyname_ex(socket.gethostname())[2]来查找指向该计算机的IP地址列表.在我管理此调用的Linux服务器上,极端慢(> 20s)...我很难理解,因为ip addr show似乎几乎立即提供了相同的信息.有什么我可以做的更快的方法吗?这可能是网络配置问题(我在路由器后面)吗?

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)?

此问题独立于IPython:

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

谢谢.

推荐答案

我遇到了类似的问题. 碰巧我的主机名是localhost.localdomain,在安装操作系统时很懒.

I had a similar problem. It happened that my hostname was localhost.localdomain, being lazy when installing the OS.

解决方案是通过sudo vi /etc/hostname为它取一个合理的名称,并将其更改为myname.mydomain,现在它以1s的速度运行.

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.

这篇关于gethostbyname_ex(hostname)非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆