From 99773282ec5101be3349d69f5628f74fe75aaeeb Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Fri, 26 Jun 2020 18:57:31 -0400 Subject: [PATCH] iostream,platform: Remove _set_nonblocking function This functionality is now provided directly in the `os` module. --- tornado/iostream.py | 9 +++------ tornado/platform/posix.py | 24 ------------------------ 2 files changed, 3 insertions(+), 30 deletions(-) delete mode 100644 tornado/platform/posix.py diff --git a/tornado/iostream.py b/tornado/iostream.py index 1fe26ae6a..92834e50a 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -59,11 +59,6 @@ if typing.TYPE_CHECKING: _IOStreamType = TypeVar("_IOStreamType", bound="IOStream") -try: - from tornado.platform.posix import _set_nonblocking -except ImportError: - _set_nonblocking = None # type: ignore - # These errnos indicate that a connection has been abruptly terminated. # They should be caught and handled less noisily than other errors. _ERRNO_CONNRESET = (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE, errno.ETIMEDOUT) @@ -1620,12 +1615,14 @@ class PipeIOStream(BaseIOStream): by `os.pipe`) rather than an open file object. Pipes are generally one-way, so a `PipeIOStream` can be used for reading or writing but not both. + + ``PipeIOStream`` is only available on Unix-based platforms. """ def __init__(self, fd: int, *args: Any, **kwargs: Any) -> None: self.fd = fd self._fio = io.FileIO(self.fd, "r+") - _set_nonblocking(fd) + os.set_blocking(fd, False) super(PipeIOStream, self).__init__(*args, **kwargs) def fileno(self) -> int: diff --git a/tornado/platform/posix.py b/tornado/platform/posix.py deleted file mode 100644 index e4699a6fc..000000000 --- a/tornado/platform/posix.py +++ /dev/null @@ -1,24 +0,0 @@ -# -# Copyright 2011 Facebook -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -"""Posix implementations of platform-specific functionality.""" - -import fcntl -import os - - -def _set_nonblocking(fd: int) -> None: - flags = fcntl.fcntl(fd, fcntl.F_GETFL) - fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) -- 2.47.2