def resolve(self, host, port, family):
"""Return list of (family, address) pairs."""
child_gr = greenlet.getcurrent()
main = child_gr.parent
assert main is not None, "Should be on child greenlet"
def handler(exc_typ, exc_val, exc_tb):
# If netutil.Resolver is configured to use TwistedResolver.
if DomainError and issubclass(exc_typ, DomainError):
exc_typ = socket.gaierror
exc_val = socket.gaierror(str(exc_val))
# Depending on the resolver implementation, we could be on any
# thread or greenlet. Return to the loop's thread and raise the
# exception on the calling greenlet from there.
self.io_loop.add_callback(functools.partial(
child_gr.throw, exc_typ, exc_val, exc_tb))
return True # Don't propagate the exception.
with stack_context.ExceptionStackContext(handler):
self.resolver.resolve(host, port, family, callback=child_gr.switch)
return main.switch()
评论列表
文章目录