Skip to content

Instantly share code, notes, and snippets.

@sideshowbarker
Created May 17, 2011 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sideshowbarker/976161 to your computer and use it in GitHub Desktop.
Save sideshowbarker/976161 to your computer and use it in GitHub Desktop.
validator build.py urllib timeout fix
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