[Twisted-Python] Async reverse DNS lookup?

exarkun at divmod.com exarkun at divmod.com
Mon Sep 27 15:03:30 MDT 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 = '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




More information about the Twisted-Python mailing list