gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

Chris Angelico rosuav at gmail.com
Mon Sep 2 06:42:12 EDT 2013


On Mon, Sep 2, 2013 at 3:28 PM,  <anntzer.lee at gmail.com> wrote:
> On Sunday, September 1, 2013 2:03:56 PM UTC-7, Chris Angelico wrote:
>
>> > I tried using netifaces (https://pypi.python.org/pypi/netifaces) which seems to rely on getifaddrs (according to the doc, I didn't check the source).  Again, it returns nearly instantaneously the correct IP address.
>>
>> Perfect!
>>
>> ChrisA
>
> Not really for my use case -- it isn't that *I* want to know my public IP address, but rather that IPython wants to know it.  Of course I could patch IPython's source to use netifaces but that sounds like an overkill.
>
> As it happens I found a better way: just add the proper entry to /etc/hosts.

Ah, I see what you mean.

If it were possible with core Python, I would recommend raising a bug
with IPython, as the current method is susceptible to external issues.
But to just get your problem solved, yes, a host file entry sounds
like it's the best way to go.

ChrisA



More information about the Python-list mailing list