summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/selector_events.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-02-04 13:51:23 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-02-04 13:51:23 (GMT)
commit2fc2313038cb2ef0f375808244783235b8ad6455 (patch)
tree1b1e1b25ac82f667d97b7b5172d9d5c2e53e019a /Lib/asyncio/selector_events.py
parentaa41b9b22b139d241dd97f8baf0fda56fe719c36 (diff)
downloadcpython-2fc2313038cb2ef0f375808244783235b8ad6455.zip
cpython-2fc2313038cb2ef0f375808244783235b8ad6455.tar.gz
cpython-2fc2313038cb2ef0f375808244783235b8ad6455.tar.bz2
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.
Diffstat (limited to 'Lib/asyncio/selector_events.py')
-rw-r--r--Lib/asyncio/selector_events.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index 7cbd4fd..a38ed1c 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -397,7 +397,8 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
raise ValueError("the socket must be non-blocking")
fut = futures.Future(loop=self)
try:
- base_events._check_resolved_address(sock, address)
+ if self._debug:
+ base_events._check_resolved_address(sock, address)
except ValueError as err:
fut.set_exception(err)
else: