2010-02-26 02:00:52 +03:00
|
|
|
`psycopg2.pool` -- Connections pooling
|
|
|
|
======================================
|
|
|
|
|
|
|
|
.. sectionauthor:: Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
|
|
|
|
|
|
|
.. index::
|
|
|
|
pair: Connection; Pooling
|
|
|
|
|
|
|
|
.. module:: psycopg2.pool
|
|
|
|
|
|
|
|
Creating new PostgreSQL connections can be an expensive operation. This
|
|
|
|
module offers a few pure Python classes implementing simple connection pooling
|
|
|
|
directly into the client application.
|
|
|
|
|
|
|
|
.. class:: AbstractConnectionPool(minconn, maxconn, \*args, \*\*kwargs)
|
|
|
|
|
|
|
|
Base class implementing generic key-based pooling code.
|
|
|
|
|
|
|
|
New *minconn* connections are created automatically. The pool will support
|
|
|
|
a maximum of about *maxconn* connections. *\*args* and *\*\*kwargs* are
|
2010-02-26 03:17:52 +03:00
|
|
|
passed to the `~psycopg2.connect()` function.
|
2010-02-26 02:00:52 +03:00
|
|
|
|
|
|
|
The following methods are expected to be implemented by subclasses:
|
|
|
|
|
|
|
|
.. method:: getconn(key=None)
|
|
|
|
|
2011-02-19 19:16:28 +03:00
|
|
|
Get a free connection and assign it to *key* if not `!None`.
|
2010-02-26 02:00:52 +03:00
|
|
|
|
2011-06-30 19:40:35 +04:00
|
|
|
.. method:: putconn(conn, key=None, close=False)
|
2010-02-26 02:00:52 +03:00
|
|
|
|
|
|
|
Put away a connection.
|
|
|
|
|
2011-06-30 19:40:35 +04:00
|
|
|
If *close* is `!True`, discard the connection from the pool.
|
|
|
|
|
2010-02-26 02:00:52 +03:00
|
|
|
.. method:: closeall
|
|
|
|
|
|
|
|
Close all the connections handled by the pool.
|
|
|
|
|
|
|
|
Notice that all the connections are closed, including ones
|
|
|
|
eventually in use by the application.
|
|
|
|
|
|
|
|
|
2010-02-26 03:17:52 +03:00
|
|
|
The following classes are `AbstractConnectionPool` subclasses ready to
|
2010-02-26 02:00:52 +03:00
|
|
|
be used.
|
|
|
|
|
|
|
|
.. autoclass:: SimpleConnectionPool
|
|
|
|
|
|
|
|
.. note:: This pool class is useful only for single-threaded applications.
|
|
|
|
|
|
|
|
|
|
|
|
.. index:: Multithread; Connection pooling
|
|
|
|
|
|
|
|
.. autoclass:: ThreadedConnectionPool
|
|
|
|
|
|
|
|
.. note:: This pool class can be safely used in multi-threaded applications.
|
|
|
|
|
|
|
|
|
|
|
|
.. autoclass:: PersistentConnectionPool
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
This pool class is mostly designed to interact with Zope and probably
|
|
|
|
not useful in generic applications.
|
|
|
|
|