Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

2013-09-02 Thread anntzer . lee
On Monday, September 2, 2013 5:45:26 AM UTC-7, Roy Smith wrote:
 In article 00843d58-db21-4cf0-9430-85362a1dd...@googlegroups.com,
  anntzer@gmail.com wrote:
 
  As it happens I found a better way: just add the proper entry to /etc/hosts.
 
 You have not found a better way.  You still have a network (or more 
 specifically, DNS) configuration that's broken.
 
 What you have found is a pragmatic way to solve your immediate problem 
 and get some work done.  That is certainly useful (and I've done it 
 plenty of times), but you need to understand that what you've done is 
 hidden the problem, not solved it.

To be honest, knowing nothing about DNS configuration, I don't even know if 
adding the entry to /etc/hosts is the proper fix or if the issue should be 
fixed somewhere else (or perhaps didn't know, as you seem to imply that that 
is not the correct way).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

2013-09-01 Thread anntzer . lee
On Saturday, August 31, 2013 10:06:43 PM UTC-7, Michael Torrie wrote:
 On 08/31/2013 10:51 PM, anntzer@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).
 
 What gethostbyname_ex and /usr/bin/hostname do are very different
 things.  gethostbyname_ex does a DNS lookup against a server.
 /usr/bin/hostname just checks a local computer setting.  I don't see why
 you are comparing the two.  /usr/bin/hostname is not going to help you
 find a list of IP addresses that point to a machine.

I was just replying to the previous comment name = socket.gethostname() see 
how long that takes and what it returns.  Then, assuming it returns a string 
containing your hostname (massive handwave about what that actually means), 
saying that gethostname resolves my own hostname instantaneously.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

2013-09-01 Thread anntzer . lee
On Sunday, September 1, 2013 4:37:34 AM UTC-7, Chris Angelico wrote:

 Yes, it most definitely CAN be a network config issue. The C function
 you want to be calling is getifaddrs(), and I don't think there's a
 way to call that from core Python. But a Google search for 'python
 getifaddrs' shows up a few third-party modules that might be of use to
 you; that'd be a lot quicker and more reliable than trying to look up
 your own hostname and depending on the results.
 
 ChrisA

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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

2013-09-01 Thread anntzer . lee
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.

Still, thanks for the suggestions.

Antony
-- 
http://mail.python.org/mailman/listinfo/python-list


gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

2013-08-31 Thread anntzer . lee
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gethostbyname_ex(hostname) extremely slow (crossposted from stackoverflow)

2013-08-31 Thread anntzer . lee
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).

On Saturday, August 31, 2013 6:01:00 PM UTC-7, Roy Smith wrote:
 In article b9f77b6f-3a65-407a-aff5-5677be2ba...@googlegroups.com,
 
  anntzer@gmail.com wrote:
 
 
 
  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)?
 
 
 
 It's almost certainly some sort of configuration issue which is causing 
 
 some DNS query to timeout.  The first step, is to figure out which part 
 
 is taking so long.  Open up a python shell and run:
 
 
 
  name = socket.gethostname()
 
 
 
 see how long that takes and what it returns.  Then, assuming it returns 
 
 a string containing your hostname (massive handwave about what that 
 
 actually means), try
 
 
 
  socket.gethostbyname_ex(name)
 
 
 
 and see how long that takes and what it returns.  At least at that point 
 
 you'll have cut the problem in half.
 
 
 
 If I had to guess, you've got a missing PTR record, because that's what 
 
 most people screw up.

-- 
http://mail.python.org/mailman/listinfo/python-list


issubclass(C, Mapping) not behaving as expected

2012-05-30 Thread anntzer . lee
from collections import *
class C(object):
def __iter__(self): pass
def __contains__(self, i): pass
def __len__(self): pass
def __getitem__(self, i): pass
issubclass(C, Mapping) = False
[issubclass(C, cls) for cls in Mapping.__mro__] = [False, True, True, True, 
True]
i.e. C does implement Sized, Iterable and Container.

I would have expected that just as issubclass(C, Sized) checks for the presence 
of a __len__ method, issubclass(C, Mapping) would check for the presence of 
the three methods required by each immediate superclass?

Antony
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cmd2, an extenstion of cmd that parses its argument list

2012-04-27 Thread anntzer . lee
On Sunday, March 18, 2012 10:12:24 PM UTC-7, anntz...@gmail.com wrote:
 Dear all,
 
 I would like to announce the first public release of cmd2, an extension of 
 the standard library's cmd with argument parsing, here: 
 https://github.com/anntzer/cmd2.
 
Due to an already existing Cmd2 on PyPI, I have renamed the project to 
parsedcmd, which is also a better description of what the module does.
https://github.com/anntzer/parsedcmd 

 Cmd2 is an extension built around the excellent cmd module of the standard
 library.  Cmd allows one to build simple custom shells using ``do_*`` methods,
 taking care in particular of the REPL loop and the interactive help.  However,
 no facility is given for parsing the argument line (do_* methods are passed 
 the
 rest of the line as a single string argument).
 
 With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's
 function annotation syntax, or with an ad-hoc ``annotate`` decorator, allowing
 the dispatcher to parse the argument list for them.
 
 Antony Lee

-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: ANN: cmd2, an extenstion of cmd that parses its argument line

2012-04-26 Thread anntzer . lee
I have renamed the project to parsedcmd, which is also a better description of 
what the module does.
https://github.com/anntzer/parsedcmd

On Monday, March 19, 2012 6:14:44 AM UTC-7, xDog Walker wrote:
 On Sunday 2012 March 18 22:11, anntzer@gmail.com wrote:
  I would like to announce the first public release of cmd2, an extension of
  the standard library's cmd with argument parsing, here:
  https://github.com/anntzer/cmd2.
 
 There already is a cmd2 package at PyPI and has been for a long time.
 
 http://packages.python.org/cmd2/
 
 -- 
 I have seen the future and I am not in it.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cmd2, an extenstion of cmd that parses its argument list

2012-04-26 Thread anntzer . lee
On Sunday, March 18, 2012 10:12:24 PM UTC-7, anntz...@gmail.com wrote:
 Dear all,
 
 I would like to announce the first public release of cmd2, an extension of 
 the standard library's cmd with argument parsing, here: 
 https://github.com/anntzer/cmd2.
 
Due to an already existing Cmd2 on PyPI, I have renamed the project to 
parsedcmd, which is also a better description of what the module does.
https://github.com/anntzer/parsedcmd 

 Cmd2 is an extension built around the excellent cmd module of the standard
 library.  Cmd allows one to build simple custom shells using ``do_*`` methods,
 taking care in particular of the REPL loop and the interactive help.  However,
 no facility is given for parsing the argument line (do_* methods are passed 
 the
 rest of the line as a single string argument).
 
 With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's
 function annotation syntax, or with an ad-hoc ``annotate`` decorator, allowing
 the dispatcher to parse the argument list for them.
 
 Antony Lee

-- 
http://mail.python.org/mailman/listinfo/python-list


cmd2, an extenstion of cmd that parses its argument list

2012-03-19 Thread anntzer . lee
Dear all,

I would like to announce the first public release of cmd2, an extension of the 
standard library's cmd with argument parsing, here: 
https://github.com/anntzer/cmd2.

Cmd2 is an extension built around the excellent cmd module of the standard
library.  Cmd allows one to build simple custom shells using ``do_*`` methods,
taking care in particular of the REPL loop and the interactive help.  However,
no facility is given for parsing the argument line (do_* methods are passed the
rest of the line as a single string argument).

With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's
function annotation syntax, or with an ad-hoc ``annotate`` decorator, allowing
the dispatcher to parse the argument list for them.

Antony Lee
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


ANN: cmd2, an extenstion of cmd that parses its argument line

2012-03-18 Thread anntzer . lee
Dear all,

I would like to announce the first public release of cmd2, an extension of the 
standard library's cmd with argument parsing, here: 
https://github.com/anntzer/cmd2.

Cmd2 is an extension built around the excellent cmd module of the standard
library.  Cmd allows one to build simple custom shells using ``do_*`` methods,
taking care in particular of the REPL loop and the interactive help.  However,
no facility is given for parsing the argument line (do_* methods are passed the
rest of the line as a single string argument).

With Cmd2, ``do_*`` methods are type-annotated, either using Python 3's
function annotation syntax, or with an ad-hoc ``annotate`` decorator, allowing
the dispatcher to parse the argument list for them.

Antony Lee
-- 
http://mail.python.org/mailman/listinfo/python-list