本文整理汇总了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 = {}
示例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)