[Twisted-Python] Async reverse DNS lookup?

exarkun at divmod.com exarkun at divmod.com
Mon Sep 27 17:03:30 EDT 2004

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 = ''
  ptr = '.'.join(addr.split('.')[::-1]) + '.in-addr.arpa'
      ).addCallback(lambda (ans, auth, add): util.println(ans[0].payload.name)
      ).addBoth(lambda r: reactor.stop()


More information about the Twisted-Python mailing list