Add correct timeout settings.

parent 35c0b582
...@@ -28,8 +28,10 @@ import urlparse ...@@ -28,8 +28,10 @@ import urlparse
# XXX: code between select/select_generic and upload/upload_generic should be # XXX: code between select/select_generic and upload/upload_generic should be
# factored # factored
# Upload/download timeout is one day # Timeout here is about timeout to CONNECT to the server (socket initialization then server answers actual data), not to retrieve/send informations.
TIMEOUT = 3600 * 24 # To be clear: it is NOT about uploading/downloading data, but about time to connect to the server, then time that server takes to start answering.
TIMEOUT = 3600
class NetworkcacheClient(object): class NetworkcacheClient(object):
''' '''
...@@ -275,7 +277,7 @@ class NetworkcacheClient(object): ...@@ -275,7 +277,7 @@ class NetworkcacheClient(object):
sha_cache_url = os.path.join(self.shacache_url, sha512sum) sha_cache_url = os.path.join(self.shacache_url, sha512sum)
request = urllib2.Request(url=sha_cache_url, data=None, request = urllib2.Request(url=sha_cache_url, data=None,
headers=self.shadir_header_dict) headers=self.shadir_header_dict)
return urllib2.urlopen(request) return urllib2.urlopen(request, timeout=TIMEOUT)
def select(self, key): def select(self, key):
''' Download a file from shacache by selecting the entry in shadir ''' Download a file from shacache by selecting the entry in shadir
...@@ -284,7 +286,7 @@ class NetworkcacheClient(object): ...@@ -284,7 +286,7 @@ class NetworkcacheClient(object):
url = os.path.join(self.shadir_url, key) url = os.path.join(self.shadir_url, key)
request = urllib2.Request(url=url, data=None, request = urllib2.Request(url=url, data=None,
headers=self.shadir_header_dict) headers=self.shadir_header_dict)
data = urllib2.urlopen(request).read() data = urllib2.urlopen(request, timeout=TIMEOUT).read()
# Filtering... # Filtering...
try: try:
data_list = json.loads(data) data_list = json.loads(data)
...@@ -323,7 +325,7 @@ class NetworkcacheClient(object): ...@@ -323,7 +325,7 @@ class NetworkcacheClient(object):
url = os.path.join(self.shadir_url, key) url = os.path.join(self.shadir_url, key)
request = urllib2.Request(url=url, data=None, request = urllib2.Request(url=url, data=None,
headers=self.shadir_header_dict) headers=self.shadir_header_dict)
data = urllib2.urlopen(request).read() data = urllib2.urlopen(request, timeout=TIMEOUT).read()
try: try:
data_list = json.loads(data) data_list = json.loads(data)
except Exception: except Exception:
...@@ -417,3 +419,4 @@ class DirectoryNotFound(Exception): ...@@ -417,3 +419,4 @@ class DirectoryNotFound(Exception):
class UploadError(Exception): class UploadError(Exception):
pass pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment