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

gevent's monkeypatching breaks timeouts on linux #1

Closed
slingamn opened this issue May 10, 2012 · 9 comments
Closed

gevent's monkeypatching breaks timeouts on linux #1

slingamn opened this issue May 10, 2012 · 9 comments

Comments

@slingamn
Copy link

See kennethreitz/requests#500 for context, but basically the timeout is no longer respected after importing the async module that monkeypatches socket.

>>> import requests
>>> import time
>>> start = time.time(); r = requests.get('http://httpbin.org/delay/4', timeout=2.0); print time.time() - start, r.status_code
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "requests/api.py", line 52, in get
    return request('get', url, **kwargs)
  File "requests/api.py", line 40, in request
    return s.request(method=method, url=url, **kwargs)
  File "requests/sessions.py", line 229, in request
    r.send(prefetch=prefetch)
  File "requests/models.py", line 604, in send
    raise Timeout('Request timed out.')
requests.exceptions.Timeout: Request timed out.
>>> start = time.time(); r = requests.get('http://httpbin.org/delay/4', timeout=2.0); print time.time() - start, r.status_code
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "requests/api.py", line 52, in get
    return request('get', url, **kwargs)
  File "requests/api.py", line 40, in request
    return s.request(method=method, url=url, **kwargs)
  File "requests/sessions.py", line 229, in request
    r.send(prefetch=prefetch)
  File "requests/models.py", line 604, in send
    raise Timeout('Request timed out.')
requests.exceptions.Timeout: Request timed out.
>>> import requests.async
>>> start = time.time(); r = requests.get('http://httpbin.org/delay/4', timeout=2.0); print time.time() - start, r.status_code
4.38320612907 200
>>> start = time.time(); r = requests.get('http://httpbin.org/delay/4', timeout=2.0); print time.time() - start, r.status_code
4.67993688583 200
@xianyunwuxin
Copy link

It seems you are using gevent 0.13.x, you can upgrade to 1.0b2(http://code.google.com/p/gevent/downloads/detail?name=gevent-1.0b2.tar.gz&can=2&q=), or using gevent's Timeout instead of requests' timeout parameter

@dhilton
Copy link

dhilton commented Jun 12, 2012

I'm seeing similar issues on Mac OSX with libevent installed via brew, gevent 1.0b2 (tried the stable release) and grequests.

@JakeAustwick
Copy link

On OSX, and also seeing this issue. The request simply hangs, and never returns. This simply brings the whole script to a halt.

Any suggestions?

Following code shows hanging behaviour:

>>> urls = ['http://www.whatzonip.com/wiki9/index.php?title=Special:UserLogin&type=signup']
>>> rs = (grequests.get(u, timeout=2) for u in urls)
>>> grequests.map(rs)

@jassinm
Copy link

jassinm commented Aug 3, 2012

all works here on macosx . on linux i tried gevent 0.13.x and 1.0b2 but still get the same error

@JakeAustwick
Copy link

You have to use the gevent on github. There has been a patch applied that fixes this, however it's not released in any format yet. Clone the gevent githubo repo and build gevent from there.

@jassinm
Copy link

jassinm commented Aug 3, 2012

thanks installed from github but JakeAustwick code for example still produces:

Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/gevent/greenlet.py", line 328, in run
    result = self._run(*self.args, **self.kwargs)
  File "/home/vagrant/.virtualenv/rotw/local/lib/python2.7/site-packages/requests/models.py", line 607, in send
    raise Timeout(e)
Timeout: HTTPConnectionPool(host='www.whatzonip.com', port=80): Request timed out. (timeout=2)
<Greenlet at 0x1c36690: <bound method Request.send of <Request [GET]>>(prefetch=True)> failed with Timeout


pip freeze | grep gevent
gevent==1.0dev

@JakeAustwick
Copy link

Huh? Isn't that correct?

The request is timing out? The problem was that timeouts were not occuring.

@jassinm
Copy link

jassinm commented Aug 3, 2012

oops my bad. did not use safe_mode=True. but that's another issue with grequests. Thanks

@jamesbennet
Copy link

Please fix this 👍

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

No branches or pull requests

7 participants