[Twisted-Python] Async reverse DNS lookup?
Yun Mao
maoy at cis.upenn.edu
Mon Sep 27 16:17:02 MDT 2004
Thank you!
Continuing on the topic of DNS lookup, does the default setting call
socket.gethostbyname() when each time I do connectTCP()? I also noticed
that my program is not responsive when DNS operation took a long time to
finish.
I took a short look into the code: the base.py says that if self.resovler
is None then it will call _internalResolve(), which calls gethostbyname().
If I am right, how to set the default resolver?
Yun
On Mon, 27 Sep 2004 exarkun at divmod.com wrote:
> On Mon, 27 Sep 2004 15:57:33 -0400 (EDT), Yun Mao <maoy at cis.upenn.edu> wrote:
> >I'm currently using socket.gethostbyaddr(ip), and sometimes it will block
> > my program for quite a while. What's the correct way to do this in
> > twisted? Do I have to create a thread for that? Thanks!
> > Yun
> >
>
> from twisted.names import client
> from twisted.python import util, log
> from twisted.internet import reactor
>
> addr = '198.49.126.190'
> ptr = '.'.join(addr.split('.')[::-1]) + '.in-addr.arpa'
> client.lookupPointer(ptr
> ).addCallback(lambda (ans, auth, add): util.println(ans[0].payload.name)
> ).addErrback(log.err
> ).addBoth(lambda r: reactor.stop()
> )
> reactor.run()
>
> Jp
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
More information about the Twisted-Python
mailing list