Search code examples
pythonurllib2geventeventlet

gevent breaks requests/urllib2 timeouts


Some time ago I wrote code that interacts with foreign service for my Django project:

    try:
        response = requests.get('some host', timeout=TIMEOUT)
    except:
        log.warning('timeout')
        return None

I tested it in my devel envierment (python manage.py runserver) and timeouts work fine. Then I decide to patch it with gevent by specifying pool implementation for gunicorn, like so:

python manage.py run_gunicorn -k gevent 

And now get call is not interrupted by timout exception. I changed pool implementation to eventlet and it works as expected:

python manage.py run_gunicorn -k eventlet

Is there any way to fix gevent?


Solution

  • I found solution here. This bug is fixed in version 1.0dev, you can install it from github:

    pip install cython
    pip install git+https://github.com/surfly/gevent.git
    

    @j-f-sebastian, thank you for hint!