Skip to content

Commit

Permalink
made the Http object used so we don't exhaust available ports for soc…
Browse files Browse the repository at this point in the history
…kets
  • Loading branch information
Jason Trost authored and jbohman committed Mar 5, 2012
1 parent 0b0ab3e commit d96a8f6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pysolr.py
Expand Up @@ -297,20 +297,23 @@ def __init__(self, url, decoder=None, timeout=60):
self.path = path.rstrip('/')
self.timeout = timeout
self.log = self._get_log()

if TIMEOUTS_AVAILABLE:
self.http = Http(timeout=self.timeout)
else:
self.http = None

def _get_log(self):
return LOG

def _send_request(self, method, path, body=None, headers=None):
if TIMEOUTS_AVAILABLE:
http = Http(timeout=self.timeout)
url = self.base_url + path

try:
start_time = time.time()
self.log.debug("Starting request to '%s' (%s) with body '%s'...",
url, method, str(body)[:10])
headers, response = http.request(url, method=method, body=body, headers=headers)
headers, response = self.http.request(url, method=method, body=body, headers=headers)
end_time = time.time()
self.log.info("Finished '%s' (%s) with body '%s' in %0.3f seconds.",
url, method, str(body)[:10], end_time - start_time)
Expand Down

0 comments on commit d96a8f6

Please sign in to comment.