Merge with Python 3.4 (asyncio)

- Close #22063: socket operations (socket,recv, sock_sendall, sock_connect,
  sock_accept) now raise an exception in debug mode if sockets are in blocking
  mode.
- asyncio: Use the new os.set_blocking() function of Python 3.5 if available
This commit is contained in:
Victor Stinner 2014-07-29 23:09:56 +02:00
commit 66565649b5
5 changed files with 48 additions and 4 deletions

View file

@ -258,6 +258,16 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
return server
if hasattr(os, 'set_blocking'):
def _set_nonblocking(fd):
os.set_blocking(fd, False)
else:
def _set_nonblocking(fd):
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
flags = flags | os.O_NONBLOCK
fcntl.fcntl(fd, fcntl.F_SETFL, flags)
class _UnixReadPipeTransport(transports.ReadTransport):
max_size = 256 * 1024 # max bytes we read in one event loop iteration
@ -273,7 +283,7 @@ class _UnixReadPipeTransport(transports.ReadTransport):
stat.S_ISSOCK(mode) or
stat.S_ISCHR(mode)):
raise ValueError("Pipe transport is for pipes/sockets only.")
os.set_blocking(self._fileno, False)
_set_nonblocking(self._fileno)
self._protocol = protocol
self._closing = False
self._loop.add_reader(self._fileno, self._read_ready)
@ -366,7 +376,7 @@ class _UnixWritePipeTransport(transports._FlowControlMixin,
stat.S_ISCHR(mode)):
raise ValueError("Pipe transport is only for "
"pipes, sockets and character devices")
os.set_blocking(self._fileno, False)
_set_nonblocking(self._fileno)
self._protocol = protocol
self._buffer = []
self._conn_lost = 0