From c8a03893d867f2ee0b48b89a531c833fa4394d0d Mon Sep 17 00:00:00 2001 From: Bob Haddleton Date: Mon, 3 May 2021 11:01:57 -0500 Subject: [PATCH 1/4] Use select.select when select.poll is not available (#327) --- httpcore/_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/httpcore/_utils.py b/httpcore/_utils.py index c77662e67..ae17d2b9c 100644 --- a/httpcore/_utils.py +++ b/httpcore/_utils.py @@ -95,8 +95,9 @@ def is_socket_readable(sock: typing.Optional[socket.socket]) -> bool: # https://github.com/python-trio/trio/blob/20ee2b1b7376db637435d80e266212a35837ddcc/trio/_socket.py#L471-L478 # See also: https://github.com/encode/httpcore/pull/193#issuecomment-703129316 - # Use select.select on Windows, and select.poll everywhere else - if sys.platform == "win32": + # Use select.select on Windows, and when poll is unavailable (e.g. eventlet is in use) + # and select.poll everywhere else + if sys.platform == "win32" or getattr(socket, 'poll', None) is None: rready, _, _ = select.select([sock_fd], [], [], 0) return bool(rready) p = select.poll() From 0ae3b25f8b45f3f6d1e654860e7bd620a033c1a1 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 4 May 2021 09:19:48 +0100 Subject: [PATCH 2/4] Update _utils.py --- httpcore/_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpcore/_utils.py b/httpcore/_utils.py index ae17d2b9c..375329c38 100644 --- a/httpcore/_utils.py +++ b/httpcore/_utils.py @@ -97,7 +97,7 @@ def is_socket_readable(sock: typing.Optional[socket.socket]) -> bool: # Use select.select on Windows, and when poll is unavailable (e.g. eventlet is in use) # and select.poll everywhere else - if sys.platform == "win32" or getattr(socket, 'poll', None) is None: + if sys.platform == "win32" or getattr(socket, "poll", None) is None: rready, _, _ = select.select([sock_fd], [], [], 0) return bool(rready) p = select.poll() From 4a33c1dbf553a29fea340061b872de780d62fc8a Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 4 May 2021 09:25:16 +0100 Subject: [PATCH 3/4] Update _utils.py --- httpcore/_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/httpcore/_utils.py b/httpcore/_utils.py index 375329c38..128c5734e 100644 --- a/httpcore/_utils.py +++ b/httpcore/_utils.py @@ -95,8 +95,8 @@ def is_socket_readable(sock: typing.Optional[socket.socket]) -> bool: # https://github.com/python-trio/trio/blob/20ee2b1b7376db637435d80e266212a35837ddcc/trio/_socket.py#L471-L478 # See also: https://github.com/encode/httpcore/pull/193#issuecomment-703129316 - # Use select.select on Windows, and when poll is unavailable (e.g. eventlet is in use) - # and select.poll everywhere else + # Use select.select on Windows, and when poll is unavailable and select.poll + # everywhere else. (E.g. When eventlet is in use. See #327) if sys.platform == "win32" or getattr(socket, "poll", None) is None: rready, _, _ = select.select([sock_fd], [], [], 0) return bool(rready) From 844542b093effc0f3b1875fe9a919c4a5528ecd0 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 4 May 2021 10:07:44 +0100 Subject: [PATCH 4/4] Update httpcore/_utils.py --- httpcore/_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/httpcore/_utils.py b/httpcore/_utils.py index 128c5734e..978b87a27 100644 --- a/httpcore/_utils.py +++ b/httpcore/_utils.py @@ -97,7 +97,7 @@ def is_socket_readable(sock: typing.Optional[socket.socket]) -> bool: # Use select.select on Windows, and when poll is unavailable and select.poll # everywhere else. (E.g. When eventlet is in use. See #327) - if sys.platform == "win32" or getattr(socket, "poll", None) is None: + if sys.platform == "win32" or getattr(select, "poll", None) is None: rready, _, _ = select.select([sock_fd], [], [], 0) return bool(rready) p = select.poll()