本文整理汇总了Python中tornado.netutil.ThreadedResolver方法的典型用法代码示例。如果您正苦于以下问题:Python netutil.ThreadedResolver方法的具体用法?Python netutil.ThreadedResolver怎么用?Python netutil.ThreadedResolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.netutil
的用法示例。
在下文中一共展示了netutil.ThreadedResolver方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: async_execute
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import ThreadedResolver [as 别名]
def async_execute(fn):
"""
新版tornado已有这个函数的实现,但是需要在class中绑定self.ioloop和self.executor,不太方便,这个版本消除了这个问题
"""
thread_resolver = ThreadedResolver()
@functools.wraps(fn)
def wrapper(self, *args, **kwargs):
callback = kwargs.pop("callback", None)
future = thread_resolver.executor.submit(fn, self, *args, **kwargs)
if callback:
IOLoop.current().add_future(future,
lambda future: callback(future.result()))
return future
return wrapper
示例2: setUp
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import ThreadedResolver [as 别名]
def setUp(self):
super(ThreadedResolverTest, self).setUp()
self.resolver = ThreadedResolver(io_loop=self.io_loop)
示例3: test_import
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import ThreadedResolver [as 别名]
def test_import(self):
TIMEOUT = 5
# Test for a deadlock when importing a module that runs the
# ThreadedResolver at import-time. See resolve_test.py for
# full explanation.
command = [
sys.executable,
'-c',
'import tornado.test.resolve_test_helper']
start = time.time()
popen = Popen(command, preexec_fn=lambda: signal.alarm(TIMEOUT))
while time.time() - start < TIMEOUT:
return_code = popen.poll()
if return_code is not None:
self.assertEqual(0, return_code)
return # Success.
time.sleep(0.05)
self.fail("import timed out")
# We do not test errors with CaresResolver:
# Some DNS-hijacking ISPs (e.g. Time Warner) return non-empty results
# with an NXDOMAIN status code. Most resolvers treat this as an error;
# C-ares returns the results, making the "bad_host" tests unreliable.
# C-ares will try to resolve even malformed names, such as the
# name with spaces used in this test.
示例4: main
# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import ThreadedResolver [as 别名]
def main():
args = parse_command_line()
if not args:
args = ['localhost', 'www.google.com',
'www.facebook.com', 'www.dropbox.com']
resolvers = [Resolver(), ThreadedResolver()]
if twisted is not None:
from tornado.platform.twisted import TwistedResolver
resolvers.append(TwistedResolver())
if pycares is not None:
from tornado.platform.caresresolver import CaresResolver
resolvers.append(CaresResolver())
family = {
'unspec': socket.AF_UNSPEC,
'inet': socket.AF_INET,
'inet6': socket.AF_INET6,
}[options.family]
for host in args:
print('Resolving %s' % host)
for resolver in resolvers:
addrinfo = yield resolver.resolve(host, 80, family)
print('%s: %s' % (resolver.__class__.__name__,
pprint.pformat(addrinfo)))
print()