class documentation

class twisted.enterprise.adbapi.ConnectionPool: (source)

View In Hierarchy

Represent a pool of connections to a DB-API 2.0 compliant database.

Instance Variable connectionFactory factory for connections, default to Connection.
Instance Variable transactionFactory factory for transactions, default to Transaction.
Instance Variable shutdownID None or a handle on the shutdown event trigger which will be used to stop the connection pool workers when the reactor stops.
Class Variable CP_ARGS Undocumented
Class Variable noisy Undocumented
Instance Variable min Undocumented
Instance Variable max Undocumented
Class Variable name Undocumented
Class Variable openfun Undocumented
Class Variable reconnect Undocumented
Class Variable good_sql Undocumented
Instance Variable running Undocumented
Method __init__ Create a new ConnectionPool.
Instance Variable dbapiName Undocumented
Instance Variable dbapi Undocumented
Instance Variable connargs Undocumented
Instance Variable connkw Undocumented
Instance Variable connections Undocumented
Instance Variable threadID Undocumented
Instance Variable threadpool Undocumented
Instance Variable startID Undocumented
Method start Start the connection pool.
Method runWithConnection Execute a function with a database connection and return the result.
Method runInteraction Interact with the database and return the result.
Method runQuery Execute an SQL query and return the result.
Method runOperation Execute an SQL query and return None.
Method close Close all pool connections and shutdown the pool.
Method finalClose This should only be called by the shutdown trigger.
Method connect Return a database connection when one becomes available.
Method disconnect Disconnect a database connection associated with this pool.
Method __getstate__ Undocumented
Method __setstate__ Undocumented
Instance Variable __dict__ Undocumented
Instance Variable _reactor The reactor which will be used to schedule startup and shutdown events.
Method _start Undocumented
Method _runWithConnection Undocumented
Method _close Undocumented
Method _runInteraction Undocumented
Method _runQuery Undocumented
Method _runOperation Undocumented
connectionFactory = (source)
factory for connections, default to Connection.
(type: any callable.)
transactionFactory = (source)
factory for transactions, default to Transaction.
(type: any callable)
shutdownID = (source)
None or a handle on the shutdown event trigger which will be used to stop the connection pool workers when the reactor stops.
_reactor = (source)
The reactor which will be used to schedule startup and shutdown events.
(type: IReactorCore provider)
CP_ARGS = (source)

Undocumented

noisy = (source)

Undocumented

(type: bool)

Undocumented

Undocumented

name = (source)

Undocumented

openfun = (source)

Undocumented

reconnect = (source)

Undocumented

(type: bool)
good_sql = (source)

Undocumented

(type: str)
running = (source)

Undocumented

(type: bool)
def __init__(self, dbapiName, *connargs, **connkw): (source)

Create a new ConnectionPool.

Any positional or keyword arguments other than those documented here are passed to the DB-API object when connecting. Use these arguments to pass database names, usernames, passwords, etc.

ParametersdbapiNamean import string to use to obtain a DB-API compatible module (e.g. 'pyPgSQL.PgSQL')
connargsUndocumented
connkwUndocumented
cp_reactoruse this reactor instead of the global reactor (added in Twisted 10.2). (type: IReactorCore provider)
cp_minthe minimum number of connections in pool (default 3)
cp_maxthe maximum number of connections in pool (default 5)
cp_noisygenerate informational log messages during operation (default False)
cp_openfuna callback invoked after every connect() on the underlying DB-API object. The callback is passed a new DB-API connection object. This callback can setup per-connection state such as charset, timezone, etc.
cp_reconnectdetect connections which have failed and reconnect (default False). Failed connections may result in ConnectionLost exceptions, which indicate the query may need to be re-sent.
cp_good_sqlan sql query which should always succeed and change no state (default 'select 1')
dbapiName = (source)

Undocumented

dbapi = (source)

Undocumented

connargs = (source)

Undocumented

connkw = (source)

Undocumented

connections = (source)

Undocumented

(type: dict)
threadID = (source)

Undocumented

threadpool = (source)

Undocumented

startID = (source)

Undocumented

def _start(self): (source)

Undocumented

def start(self): (source)

Start the connection pool.

If you are using the reactor normally, this function does *not* need to be called.

def runWithConnection(self, func, *args, **kw): (source)

Execute a function with a database connection and return the result.

ParametersfuncA callable object of one argument which will be executed in a thread with a connection from the pool. It will be passed as its first argument a Connection instance (whose interface is mostly identical to that of a connection object for your DB-API module of choice), and its results will be returned as a Deferred. If the method raises an exception the transaction will be rolled back. Otherwise, the transaction will be committed. Note that this function is not run in the main thread: it must be threadsafe.
argspositional arguments to be passed to func
kwkeyword arguments to be passed to func
Returnsa Deferred which will fire the return value of func(Transaction(...), *args, **kw), or a twisted.python.failure.Failure.
def _runWithConnection(self, func, *args, **kw): (source)

Undocumented

def runInteraction(self, interaction, *args, **kw): (source)

Interact with the database and return the result.

The 'interaction' is a callable object which will be executed in a thread using a pooled connection. It will be passed an Transaction object as an argument (whose interface is identical to that of the database cursor for your DB-API module of choice), and its results will be returned as a Deferred. If running the method raises an exception, the transaction will be rolled back. If the method returns a value, the transaction will be committed.

NOTE that the function you pass is *not* run in the main thread: you may have to worry about thread-safety in the function you pass to this if it tries to use non-local objects.

Parametersinteractiona callable object whose first argument is an adbapi.Transaction.
argsadditional positional arguments to be passed to interaction
kwkeyword arguments to be passed to interaction
Returnsa Deferred which will fire the return value of interaction(Transaction(...), *args, **kw), or a twisted.python.failure.Failure.
def runQuery(self, *args, **kw): (source)

Execute an SQL query and return the result.

A DB-API cursor which will be invoked with cursor.execute(*args, **kw). The exact nature of the arguments will depend on the specific flavor of DB-API being used, but the first argument in *args be an SQL statement. The result of a subsequent cursor.fetchall() will be fired to the Deferred which is returned. If either the 'execute' or 'fetchall' methods raise an exception, the transaction will be rolled back and a twisted.python.failure.Failure returned.

The *args and **kw arguments will be passed to the DB-API cursor's 'execute' method.

Returnsa Deferred which will fire the return value of a DB-API cursor's 'fetchall' method, or a twisted.python.failure.Failure.
def runOperation(self, *args, **kw): (source)

Execute an SQL query and return None.

A DB-API cursor which will be invoked with cursor.execute(*args, **kw). The exact nature of the arguments will depend on the specific flavor of DB-API being used, but the first argument in *args will be an SQL statement. This method will not attempt to fetch any results from the query and is thus suitable for INSERT, DELETE, and other SQL statements which do not return values. If the 'execute' method raises an exception, the transaction will be rolled back and a Failure returned.

The *args and *kw arguments will be passed to the DB-API cursor's 'execute' method.

Returnsa Deferred which will fire with None or a twisted.python.failure.Failure.
def close(self): (source)

Close all pool connections and shutdown the pool.

def finalClose(self): (source)

This should only be called by the shutdown trigger.

def connect(self): (source)

Return a database connection when one becomes available.

This method blocks and should be run in a thread from the internal threadpool. Don't call this method directly from non-threaded code. Using this method outside the external threadpool may exceed the maximum number of connections in the pool.

Returnsa database connection from the pool.
def disconnect(self, conn): (source)

Disconnect a database connection associated with this pool.

Note: This function should only be used by the same thread which called ConnectionPool.connect. As with connect, this function is not used in normal non-threaded Twisted code.

def _close(self, conn): (source)

Undocumented

def _runInteraction(self, interaction, *args, **kw): (source)

Undocumented

def _runQuery(self, trans, *args, **kw): (source)

Undocumented

def _runOperation(self, trans, *args, **kw): (source)

Undocumented

def __getstate__(self): (source)

Undocumented

def __setstate__(self, state): (source)

Undocumented

__dict__ = (source)

Undocumented

API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.