AttributeError after gevent.monkey.patch_select()

Requests-2.13 fails with `AttributeError` because there's no `select.epoll()` when `gevent` monkey-patched `select`.

This issue is actually a bug from urllib3-1.20.  It depends on `select.epoll()` and it doesn't handle `AttributeError`.  But `gevent.monkey.patch_select()` removes `epoll`, `kqueue`, `kevent`, and `devpoll` to make some modules non-blocking.

```
Traceback (most recent call last):
  ...
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 588, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 241, in _get_conn
    if conn and is_connection_dropped(conn):
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/packages/urllib3/util/connection.py", line 27, in is_connection_dropped
    return bool(wait_for_read(sock, timeout=0.0))
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/packages/urllib3/util/wait.py", line 33, in wait_for_read
    return _wait_for_io_events(socks, EVENT_READ, timeout)
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/packages/urllib3/util/wait.py", line 22, in _wait_for_io_events
    with DefaultSelector() as selector:
  File "/home/sub/env/local/lib/python2.7/site-packages/requests/packages/urllib3/util/selectors.py", line 364, in __init__
    self._epoll = select.epoll()
AttributeError: 'module' object has no attribute 'epoll'
```

When are you patching with gevent? urllib3 should absolutely tolerate not having an epoll implementation. The epoll implementation is only chosen when `hasattr(select, 'epoll')` is `True`. I suspect you are importing requests before you patch with gevent. When working with gevent you *must* monkey patch before you import other modules, especially if the monkey patch is going to delete items.

There is no really good way for urllib3 to tolerate the possibility that a selector may disappear sometime between import time and class creation time.

As a more general note, I don't believe that library authors are required to make their libraries resilient in the face of monkey patching: I believe it is incumbent on monkey patch authors and users to make their patches resilient in the face of what libraries do.

In this case, urllib3 makes the reasonable decision to check for implementations at import time, because urllib3 rightly judges that it is absurd that we could have an epoll implementation at time *x* but not at time *x + n ∀ n > 0*. epoll implementations don't vanish on systems that aren't being messed with. :wink:

In this case, as noted above, the simple fix is to simply monkey patch before you import other modules. This is good practice with gevent as many other modules do import-time feature detection.

I agree to you.  There was something which imports `requests` before monkey-patching.  This should not be fixed by Requests own.  I close this issue.

I agree that monkey patching has to be done before everything. I have a django app running with uwsgi+supervisord config. And `gevent.monkey.patch_all()` was the first line of wsgi.py (which is the entry point to the app).  But still this exception was thrown. So either adding `--gevent-early-monkey-patch` in the uwsgi config or  `gevent.monkey.patch_all(select=False)` in the wsgi.py fixed the error. I'm not sure that this is relevant to the requests or urllib3 libs but just for someone's information.