當前位置: 首頁>>代碼示例>>Python>>正文


Python netutil.ThreadedResolver方法代碼示例

本文整理匯總了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 
開發者ID:mqingyn,項目名稱:torngas,代碼行數:18,代碼來源:async_execute.py

示例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) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:5,代碼來源:netutil_test.py

示例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. 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:31,代碼來源:netutil_test.py

示例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() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:32,代碼來源:test_resolvers.py


注:本文中的tornado.netutil.ThreadedResolver方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。