monkey_patches: work around Python issue 33678. Closes #1016

This commit is contained in:
Sebastien Bourdeauducq 2018-05-29 17:51:41 +08:00
parent 2e09307d8d
commit d1df18ae6a
1 changed files with 24 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import sys import sys
import socket
__all__ = [] __all__ = []
@ -11,3 +12,26 @@ if sys.version_info[:3] >= (3, 5, 2):
def _ipaddr_info(host, port, family, type, proto): def _ipaddr_info(host, port, family, type, proto):
return None return None
asyncio.base_events._ipaddr_info = _ipaddr_info asyncio.base_events._ipaddr_info = _ipaddr_info
# See https://github.com/m-labs/artiq/issues/1016
@asyncio.coroutine
def sock_connect(self, sock, address):
"""Connect to a remote socket at address.
This method is a coroutine.
"""
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
if not hasattr(socket, 'AF_UNIX') or sock.family != socket.AF_UNIX:
socktype = sock.type & 0xf # WA https://bugs.python.org/issue21327
resolved = asyncio.base_events._ensure_resolved(
address, family=sock.family, type=socktype, proto=sock.proto, loop=self)
if not resolved.done():
yield from resolved
_, _, _, _, address = resolved.result()[0]
fut = self.create_future()
self._sock_connect(fut, sock, address)
return (yield from fut)
asyncio.selector_events.BaseSelectorEventLoop.sock_connect = sock_connect