mirror of
https://github.com/python/cpython.git
synced 2025-12-10 02:50:09 +00:00
asyncio: Only call _check_resolved_address() in debug mode
* _check_resolved_address() is implemented with getaddrinfo() which is slow * If available, use socket.inet_pton() instead of socket.getaddrinfo(), because it is much faster Microbenchmark (timeit) on Fedora 21 (Python 3.4, Linux 3.17, glibc 2.20) to validate the IPV4 address "127.0.0.1" or the IPv6 address "::1": * getaddrinfo() 10.4 usec per loop * inet_pton(): 0.285 usec per loop On glibc older than 2.14, getaddrinfo() always requests the list of all local IP addresses to the kernel (using a NETLINK socket). getaddrinfo() has other known issues, it's better to avoid it when it is possible.
This commit is contained in:
parent
aa41b9b22b
commit
2fc2313038
4 changed files with 40 additions and 18 deletions
|
|
@ -437,7 +437,8 @@ class BaseProactorEventLoop(base_events.BaseEventLoop):
|
|||
|
||||
def sock_connect(self, sock, address):
|
||||
try:
|
||||
base_events._check_resolved_address(sock, address)
|
||||
if self._debug:
|
||||
base_events._check_resolved_address(sock, address)
|
||||
except ValueError as err:
|
||||
fut = futures.Future(loop=self)
|
||||
fut.set_exception(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue