Created
May 17, 2011 08:36
-
-
Save sideshowbarker/976161 to your computer and use it in GitHub Desktop.
validator build.py urllib timeout fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r b893eb8c0260 build.py | |
--- a/build.py Sat Feb 12 20:51:26 2011 +0000 | |
+++ b/build.py Tue May 17 17:35:45 2011 +0900 | |
@@ -25,6 +25,7 @@ | |
import shutil | |
import httplib | |
import urllib2 | |
+import socket | |
import re | |
try: | |
from hashlib import md5 | |
@@ -643,14 +644,18 @@ | |
# I bet there's a way to do this with more efficient IO and less memory | |
print url | |
completed = False | |
+ defaultTimeout = socket.getdefaulttimeout() | |
while not completed: | |
try: | |
- f = urllib2.urlopen(url, timeout=httpTimeoutSeconds) | |
+ socket.setdefaulttimeout(httpTimeoutSeconds) | |
+ f = urllib2.urlopen(url) | |
data = f.read() | |
f.close() | |
completed = True | |
except httplib.BadStatusLine, e: | |
print "received error, retrying" | |
+ finally: | |
+ socket.setdefaulttimeout(defaultTimeout) | |
if md5sum: | |
m = md5(data) | |
if md5sum != m.hexdigest(): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment