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

No good way to tell when a timeout occurred #3

Open
jjlee opened this issue Nov 27, 2009 · 2 comments
Open

No good way to tell when a timeout occurred #3

jjlee opened this issue Nov 27, 2009 · 2 comments

Comments

@jjlee
Copy link
Owner

jjlee commented Nov 27, 2009

Got: When you request a timeout using the timeout parameter to urlopen (or Browser.open), in order to tell that a timeout occurred, you have to use a poorly-defined interface like HTTPError.reason, using code like this:

import mechanize
import socket
br = mechanize.Browser()
try:
br.open("http://python.org/", timeout=0.001)
except mechanize.URLError, exc:
if isinstance(exc.reason, socket.timeout):
print "timeout occurred"

Expect: There's some clearly defined iinterface for finding out that a timeout imposed by module socket occurred.

@jjlee
Copy link
Owner Author

jjlee commented Nov 27, 2009

Here's that snippet again, I hope formatted correctly this time:

import mechanize
import socket
br = mechanize.Browser()
try:
    br.open("http://python.org/", timeout=0.001)
except mechanize.URLError, exc:
    if isinstance(exc.reason, socket.timeout):
        print "timeout occurred"

@jjlee
Copy link
Owner Author

jjlee commented Nov 27, 2009

This is an issue inherited from urllib2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant