diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-29 23:09:56 +0200 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-29 23:09:56 +0200 |
commit | 66565649b53b39a11306d96935be8a4810a70f3f (patch) | |
tree | 852dc7f6f6272a6cfb1433a3067dac569adb3d08 /Lib/asyncio/unix_events.py | |
parent | acc6e7596f515c2e0a3376a5ef647f531f22a824 (diff) | |
parent | 9c9f1f10d391ff3458a80fc3d0110870d50012e2 (diff) | |
download | cpython-git-66565649b53b39a11306d96935be8a4810a70f3f.tar.gz |
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
Diffstat (limited to 'Lib/asyncio/unix_events.py')
-rw-r--r-- | Lib/asyncio/unix_events.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 665901ad26..94a46d094c 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -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 |