Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reverted e86de36 - Reuse a single connection when doing a bucket list

We need a more generic approach to connection pooling.
  • Loading branch information...
commit de9ffcb493c9ccdd29b870b59018918819070b34 1 parent 12acd8a
@mludvig mludvig authored
Showing with 6 additions and 16 deletions.
  1. +6 −16 S3/S3.py
View
22 S3/S3.py
@@ -246,10 +246,9 @@ def _get_common_prefixes(data):
truncated = True
list = []
prefixes = []
- conn = self.get_connection(bucket)
while truncated:
- response = self.bucket_list_noparse(conn, bucket, prefix, recursive, uri_params)
+ response = self.bucket_list_noparse(bucket, prefix, recursive, uri_params)
current_list = _get_contents(response["data"])
current_prefixes = _get_common_prefixes(response["data"])
truncated = _list_truncated(response["data"])
@@ -263,19 +262,17 @@ def _get_common_prefixes(data):
list += current_list
prefixes += current_prefixes
- conn.close()
-
response['list'] = list
response['common_prefixes'] = prefixes
return response
- def bucket_list_noparse(self, connection, bucket, prefix = None, recursive = None, uri_params = {}):
+ def bucket_list_noparse(self, bucket, prefix = None, recursive = None, uri_params = {}):
if prefix:
uri_params['prefix'] = self.urlencode_string(prefix)
if not self.config.recursive and not recursive:
uri_params['delimiter'] = "/"
request = self.create_request("BUCKET_LIST", bucket = bucket, **uri_params)
- response = self.send_request(request, conn = connection)
+ response = self.send_request(request)
#debug(response)
return response
@@ -662,7 +659,7 @@ def _fail_wait(self, retries):
# Wait a few seconds. The more it fails the more we wait.
return (self._max_retries - retries + 1) * 3
- def send_request(self, request, body = None, retries = _max_retries, conn = None):
+ def send_request(self, request, body = None, retries = _max_retries):
method_string, resource, headers = request.get_triplet()
debug("Processing request, please wait...")
if not headers.has_key('content-length'):
@@ -671,13 +668,7 @@ def send_request(self, request, body = None, retries = _max_retries, conn = None
# "Stringify" all headers
for header in headers.keys():
headers[header] = str(headers[header])
- if conn is None:
- debug("Establishing connection")
- conn = self.get_connection(resource['bucket'])
- close_conn = True
- else:
- debug("Using existing connection")
- close_conn = False
+ conn = self.get_connection(resource['bucket'])
uri = self.format_uri(resource)
debug("Sending request method_string=%r, uri=%r, headers=%r, body=(%i bytes)" % (method_string, uri, headers, len(body or "")))
conn.request(method_string, uri, body, headers)
@@ -688,8 +679,7 @@ def send_request(self, request, body = None, retries = _max_retries, conn = None
response["headers"] = convertTupleListToDict(http_response.getheaders())
response["data"] = http_response.read()
debug("Response: " + str(response))
- if close_conn is True:
- conn.close()
+ conn.close()
except Exception, e:
if retries:
warning("Retrying failed request: %s (%s)" % (resource['uri'], e))
Please sign in to comment.
Something went wrong with that request. Please try again.