addressed maintainer comments
This commit is contained in:
@@ -1,14 +1,20 @@
|
|||||||
from Queue import Queue
|
try:
|
||||||
|
import queue
|
||||||
|
except ImportError:
|
||||||
|
import Queue as queue
|
||||||
from .base import Connection
|
from .base import Connection
|
||||||
|
|
||||||
|
|
||||||
class PoolingConnection(Connection):
|
class PoolingConnection(Connection):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self._free_connections = Queue()
|
self._free_connections = queue.Queue()
|
||||||
super(PoolingConnection, self).__init__(*args, **kwargs)
|
super(PoolingConnection, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def _get_connection(self):
|
def _get_connection(self):
|
||||||
return self._make_connection() if self._free_connections.empty() else self._free_connections.get()
|
try:
|
||||||
|
return self._free_connections.get_nowait()
|
||||||
|
except queue.Empty:
|
||||||
|
return self._make_connection()
|
||||||
|
|
||||||
def _release_connection(self, con):
|
def _release_connection(self, con):
|
||||||
self._free_connections.put(con)
|
self._free_connections.put(con)
|
||||||
@@ -65,7 +65,7 @@ class ThriftConnection(PoolingConnection):
|
|||||||
except (TException, SocketTimeout) as e:
|
except (TException, SocketTimeout) as e:
|
||||||
self.log_request_fail(method, url, body, time.time() - start, exception=e)
|
self.log_request_fail(method, url, body, time.time() - start, exception=e)
|
||||||
raise ConnectionError('N/A', str(e), e)
|
raise ConnectionError('N/A', str(e), e)
|
||||||
|
finally:
|
||||||
if tclient:
|
if tclient:
|
||||||
self._release_connection(tclient)
|
self._release_connection(tclient)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user