2014-09-23 01:13:04 +12:00
|
|
|
try:
|
|
|
|
|
import queue
|
|
|
|
|
except ImportError:
|
|
|
|
|
import Queue as queue
|
2013-08-25 17:00:46 +02:00
|
|
|
from .base import Connection
|
|
|
|
|
|
2014-09-19 01:45:03 +12:00
|
|
|
|
2013-08-25 17:00:46 +02:00
|
|
|
class PoolingConnection(Connection):
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2014-09-23 01:13:04 +12:00
|
|
|
self._free_connections = queue.Queue()
|
2013-08-25 17:00:46 +02:00
|
|
|
super(PoolingConnection, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
def _get_connection(self):
|
2014-09-23 01:13:04 +12:00
|
|
|
try:
|
|
|
|
|
return self._free_connections.get_nowait()
|
|
|
|
|
except queue.Empty:
|
|
|
|
|
return self._make_connection()
|
2013-08-25 17:00:46 +02:00
|
|
|
|
|
|
|
|
def _release_connection(self, con):
|
2015-03-23 15:25:45 -07:00
|
|
|
self._free_connections.put(con)
|