def __init__(self, dbapi, maxconnections, *args, **kwargs):
        """Set up the database connection pool.

        dbapi: the DB-API 2 compliant module you want to use
        maxconnections: the number of connections cached in the pool
        args, kwargs: the parameters that shall be used to establish
            the database connections using connect()

        """
        try:
            threadsafety = dbapi.threadsafety
        except Exception:
            threadsafety = None
        if threadsafety == 0:
            raise NotSupportedError(
                "Database module does not support any level of threading.")
        elif threadsafety == 1:
            # If there is no connection level safety, build
            # the pool using the synchronized queue class
            # that implements all the required locking semantics.
            try:
                from Queue import Queue
            except ImportError:  # Python 3
                from queue import Queue
            self._queue = Queue(maxconnections)  # create the queue
            self.connection = self._unthreadsafe_get_connection
            self.addConnection = self._unthreadsafe_add_connection
            self.returnConnection = self._unthreadsafe_return_connection
        elif threadsafety in (2, 3):
            # If there is connection level safety, implement the
            # pool with an ordinary list used as a circular buffer.
            # We only need a minimum of locking in this case.
            from threading import Lock
            self._lock = Lock()  # create a lock object to be used later
            self._nextConnection = 0  # index of the next connection to be used
            self._connections = []  # the list of connections
            self.connection = self._threadsafe_get_connection
            self.addConnection = self._threadsafe_add_connection
            self.returnConnection = self._threadsafe_return_connection
        else:
            raise NotSupportedError(
                "Database module threading support cannot be determined.")
        # Establish all database connections (it would be better to
        # only establish a part of them now, and the rest on demand).
        for i in range(maxconnections):
            self.addConnection(dbapi.connect(*args, **kwargs))
def __init__ ( self , dbapi , maxconnections , * args , ** kwargs ) : try : threadsafety = dbapi . threadsafety except Exception : threadsafety = None if threadsafety == 0 : raise NotSupportedError ( "Database module does not support any level of threading." ) elif threadsafety == 1 : try : from Queue import Queue except ImportError : from queue import Queue self . _queue = Queue ( maxconnections ) self . connection = self . _unthreadsafe_get_connection self . addConnection = self . _unthreadsafe_add_connection self . returnConnection = self . _unthreadsafe_return_connection elif threadsafety in ( 2 , 3 ) : from threading import Lock self . _lock = Lock ( ) self . _nextConnection = 0 self . _connections = [ ] self . connection = self . _threadsafe_get_connection self . addConnection = self . _threadsafe_add_connection self . returnConnection = self . _threadsafe_return_connection else : raise NotSupportedError ( "Database module threading support cannot be determined." ) for i in range ( maxconnections ) : self . addConnection ( dbapi . connect ( * args , ** kwargs ) )
Set up the database connection pool.

        dbapi: the DB-API 2 compliant module you want to use
        maxconnections: the number of connections cached in the pool
        args, kwargs: the parameters that shall be used to establish
            the database connections using connect()