Created
May 4, 2011 17:37
-
-
Save jevinskie/955631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@defer.inlineCallbacks | |
def query(): | |
reactor.run() | |
r = yield resolver.lookupAddress('google.com') | |
reactor.stop() | |
return socket.inet_ntop(socket.AF_INET6, r[0][0].payload.address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from threading import Thread
from twisted.internet import reactor
from twisted.internet.threads import blockingCallFromThread
from twisted.names.client import resolver
running = False
def query():
global running
if not running:
Thread(target=reactor.run, args=()).start()
return blockingCallFromThread(resolver.lookupAddress, 'google.com')