Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select.poll() is not available when using eventlet #327

Closed
bobh66 opened this issue May 3, 2021 · 2 comments · Fixed by #331
Closed

select.poll() is not available when using eventlet #327

bobh66 opened this issue May 3, 2021 · 2 comments · Fixed by #331

Comments

@bobh66
Copy link
Contributor

bobh66 commented May 3, 2021

When using httpx/httpcore and eventlet together, is_socket_readable() fails with an AttributeError because poll() is not implemented in eventlet:

File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1130, in patch
    return self.request(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 747, in request
    return self.send(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 831, in send
    response = self._send_handling_auth(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 866, in _send_handling_auth
    response = self._send_handling_redirects(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 900, in _send_handling_redirects
    response = self._send_single_request(request, timeout)
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 934, in _send_single_request
    (status_code, headers, stream, extensions) = transport.handle_request(
  File "/usr/local/lib/python3.8/site-packages/httpx/_transports/default.py", line 179, in handle_request
    status_code, headers, byte_stream, extensions = self._pool.handle_request(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 212, in handle_request
    connection = self._get_connection_from_pool(origin)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 254, in _get_connection_from_pool
    if connection.is_socket_readable():
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 172, in is_socket_readable
    return self.connection is not None and self.connection.is_socket_readable()
  File "/usr/local/lib/python3.8/site-packages/httpcore/_sync/http11.py", line 215, in is_socket_readable
    return self.socket.is_readable()
  File "/usr/local/lib/python3.8/site-packages/httpcore/_backends/sync.py", line 82, in is_readable
    return is_socket_readable(self.sock)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_utils.py", line 102, in is_socket_readable
    p = select.poll()

Since this code already uses select.select() instead of select.poll() on Windows, I will push a PR to also use select.select() if poll() is unavailable.

@tomchristie
Copy link
Member

Could you provide a minimal example that can be used to reproduce this?

@bobh66
Copy link
Contributor Author

bobh66 commented May 3, 2021

This seems to do it pretty reliably. Increasing the loop count causes the connection pool to get used up which triggers the problem:

eventlet.monkey_patch()

import httpx

client = httpx.Client()

for x in range(1, 10):
    client.get('http://www.google.com')
Traceback (most recent call last):
  File "/home/bobh/testhttpcore.py", line 9, in <module>
    client.get('http://www.google.com')
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_client.py", line 975, in get
    return self.request(
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_client.py", line 747, in request
    return self.send(
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_client.py", line 831, in send
    response = self._send_handling_auth(
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_client.py", line 866, in _send_handling_auth
    response = self._send_handling_redirects(
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_client.py", line 900, in _send_handling_redirects
    response = self._send_single_request(request, timeout)
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_client.py", line 934, in _send_single_request
    (status_code, headers, stream, extensions) = transport.handle_request(
  File "/home/bobh/PyCharmProjects/python-backend/.tox/dev/lib/python3.8/site-packages/httpx/_transports/default.py", line 179, in handle_request
    status_code, headers, byte_stream, extensions = self._pool.handle_request(
  File "/home/bobh/git/httpcore/httpcore/_sync/http_proxy.py", line 115, in handle_request
    return self._forward_request(
  File "/home/bobh/git/httpcore/httpcore/_sync/http_proxy.py", line 145, in _forward_request
    connection = self._get_connection_from_pool(origin)
  File "/home/bobh/git/httpcore/httpcore/_sync/connection_pool.py", line 254, in _get_connection_from_pool
    if connection.is_socket_readable():
  File "/home/bobh/git/httpcore/httpcore/_sync/connection.py", line 172, in is_socket_readable
    return self.connection is not None and self.connection.is_socket_readable()
  File "/home/bobh/git/httpcore/httpcore/_sync/http11.py", line 212, in is_socket_readable
    return self.socket.is_readable()
  File "/home/bobh/git/httpcore/httpcore/_backends/sync.py", line 82, in is_readable
    return is_socket_readable(self.sock)
 File "/home/bobh/git/httpcore/httpcore/_utils.py", line 103, in is_socket_readable
    p = select.poll()
AttributeError: module 'select' has no attribute 'poll'

bobh66 added a commit to bobh66/httpcore that referenced this issue May 3, 2021
tomchristie added a commit that referenced this issue May 4, 2021
* Use select.select when select.poll is not available (#327)

* Update _utils.py

* Update _utils.py

* Update httpcore/_utils.py

Co-authored-by: Tom Christie <tom@tomchristie.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants