当前位置: 首页>>代码示例>>Python>>正文


Python pycares.Channel方法代码示例

本文整理汇总了Python中pycares.Channel方法的典型用法代码示例。如果您正苦于以下问题:Python pycares.Channel方法的具体用法?Python pycares.Channel怎么用?Python pycares.Channel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycares的用法示例。


在下文中一共展示了pycares.Channel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initialize

# 需要导入模块: import pycares [as 别名]
# 或者: from pycares import Channel [as 别名]
def initialize(self, io_loop=None):
        self.io_loop = io_loop or IOLoop.current()
        self.channel = pycares.Channel(sock_state_cb=self._sock_state_cb)
        self.fds = {} 
开发者ID:DirceuSilvaLabs,项目名称:noc-orchestrator,代码行数:6,代码来源:caresresolver.py

示例2: resolve_cares

# 需要导入模块: import pycares [as 别名]
# 或者: from pycares import Channel [as 别名]
def resolve_cares(name):
    # create new c-ares channel
    careschan = pycares.Channel(timeout=DNS_TIMEOUT, tries=1)

    # if we don't get a response we return the default value
    result = Resultholder()
    result.value = DNS_TIMEOUT_VALUE

    def setresult_cb(res, error):
        # ignore error and just take first result ip (randomized anyway)
        if res and res.addresses:
            result.value = res.addresses[0]

    # resolve with cb
    careschan.gethostbyname(name, socket.AF_INET, setresult_cb)

    # now do the actual work
    readfds, writefds = careschan.getsock()
    canreadfds, canwritefds, _ = select.select(readfds, writefds, [],
                                               DNS_TIMEOUT)
    for rfd in canreadfds:
        careschan.process_fd(rfd, -1)

    # if the query did not succeed, setresult was not called and we just
    # return result destroy the channel first to not leak anything
    careschan.destroy()
    return result.value

# workaround until py3 nonlocal (for c-ares and gevent) 
开发者ID:ctxis,项目名称:CAPE,代码行数:31,代码来源:dns.py


注:本文中的pycares.Channel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。