gevent.resolver.ares – c-ares based hostname resolver¶
c-ares based hostname resolver.
- class Resolver(hub=None, use_environ=True, **kwargs)[source]¶
Bases:
AbstractResolverImplementation of the resolver API using the c-ares library.
This implementation uses the c-ares library to handle name resolution. c-ares is natively asynchronous at the socket level and so integrates well into gevent’s event loop.
In comparison to
gevent.resolver_thread.Resolver(which delegates to the native system resolver), the implementation is much more complex. In addition, there have been reports of it not properly honoring certain system configurations (for example, the order in which IPv4 and IPv6 results are returned may not match the threaded resolver). However, because it does not use threads, it may scale better for applications that make many lookups.There are some known differences from the system resolver.
gethostbyname_exandgethostbyaddrmay return different for thealiaslisttuple member. (Sometimes the same, sometimes in a different order, sometimes a different alias altogether.)gethostbyname_exmay return theipaddrlistin a different order.getaddrinfodoes not returnSOCK_RAWresults.getaddrinfomay return results in a different order.Handling of
.local(mDNS) names may be different, even if they are listed in the hosts file.c-ares will not resolve
broadcasthost, even if listed in the hosts file prior to 2020-04-30.This implementation may raise
gaierror(4)where the system implementation would raiseherror(1)or vice versa, with different error numbers. However, after 2020-04-30, this should be much reduced.The results for
localhostmay be different. In particular, some system resolvers will return more results fromgetaddrinfothan c-ares does, such as SOCK_DGRAM results, and c-ares may report more ips on a multi-homed host.The system implementation may return some names fully qualified, where this implementation returns only the host name. This appears to be the case only with entries found in
/etc/hosts.c-ares supports a limited set of flags for
getnameinfoandgetaddrinfo; unknown flags are ignored. System-specific flags such asAI_V4MAPPED_CFGare not supported.getaddrinfomay return canonical names even without theAI_CANONNAMEbeing set.getaddrinfodoes not appear to support IPv6 symbolic scope IDs.
Caution
This module is considered extremely experimental on PyPy, and due to its implementation in cython, it may be slower. It may also lead to interpreter crashes.
Changed in version 1.5.0: This version of gevent typically embeds c-ares 1.15.0 or newer. In that version of c-ares, domains ending in
.onionare never resolved or even sent to the DNS server.Changed in version 20.5.0:
getaddrinfois now implemented using the native c-ares function from c-ares 1.16 or newer.Changed in version 20.5.0: Now
herrorandgaierrorare raised more consistently with the standard library resolver, and have more consistent errno values.Handling of localhost and broadcast names is now more consistent.
Changed in version 22.10.1: Now has a
__del__method that warns if the object is destroyed without being properly closed.