Skip to content

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

Closed

Description

@bobh66

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.

Activity

  1. lovelydinosaur commented on May 3, 2021

    @lovelydinosaur
    Member

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

  2. bobh66 commented on May 3, 2021

    @bobh66
    ContributorAuthor

    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'
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions